File: CSSPrimitiveValue.t

package info (click to toggle)
libcss-dom-perl 0.15-1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 716 kB
  • ctags: 249
  • sloc: perl: 7,310; makefile: 2
file content (669 lines) | stat: -rw-r--r-- 25,614 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
#!/usr/bin/perl -T

use strict; use warnings;
no warnings<utf8 parenthesis regexp once qw bareword syntax>;
our $tests;
BEGIN { ++$INC{'tests.pm'} }
sub tests'VERSION { $tests += pop };
sub tests'import  { $tests += pop if @_ > 1 };
use Test::More;
plan tests => $tests;

use tests 1; # use
use_ok 'CSS::DOM::Value::Primitive', ':all';

use tests 26; # constants
{
	my $x;

	for (qw/ UNKNOWN NUMBER PERCENTAGE EMS EXS PX CM MM IN PT PC DEG
	         RAD GRAD MS S HZ KHZ DIMENSION STRING URI IDENT ATTR
	         COUNTER RECT RGBCOLOR /) {
		eval "is CSS_$_, " . $x++ . ", '$_'";
	}
}

use CSS::DOM;

#use tests 1; # unknown
# ~~~ How do we get an unknown primitive value? If we have a value that is
#     unrecognised, what determines whether it becomes a custom value or
#     an unknown primitive value? What should I test for?

# This sub runs two tests
sub test_isa {
 isa_ok $_[0], 'CSS::DOM::Value::Primitive', $_[1];
 ok $_[0]->DOES('CSS::DOM::Value'), "$_[1] DOES CSS::DOM::Value";
}

# -------------------------------------
# Tests for isa, primitiveType and get*

use tests 7; # numbers
for(CSS::DOM::Value::Primitive->new(type => &CSS_NUMBER, value => 73)) {
 test_isa $_, 'number value';
 is $_->primitiveType, &CSS_NUMBER, 'number->primitiveType';
 is $_->getFloatValue, 73, 'number->getFloatValue';
 ok !eval{ $_->getStringValue;1}, 'number->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after number->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after number->getStringValue dies';
}

use tests 7; # %
for(
 CSS::DOM::Value::Primitive->new(type => &CSS_PERCENTAGE, value => 73)
) {
 test_isa $_, '% value';
 is $_->primitiveType, &CSS_PERCENTAGE, '%->primitiveType';
 is $_->getFloatValue, 73, '%->getFloatValue';
 ok !eval{ $_->getStringValue;1}, '%->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after %->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after %->getStringValue dies';
}

use tests 7; # M
for(CSS::DOM::Value::Primitive->new(type => &CSS_EMS, value => 73)) {
 test_isa $_, 'em value';
 is $_->primitiveType, &CSS_EMS, 'em->primitiveType';
 is $_->getFloatValue, 73, 'em->getFloatValue';
 ok !eval{ $_->getStringValue;1}, 'em->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after em->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after em->getStringValue dies';
}

use tests 7; # X
for(CSS::DOM::Value::Primitive->new(type => &CSS_EXS, value => 73)) {
 test_isa $_, 'ex value';
 is $_->primitiveType, &CSS_EXS, 'ex->primitiveType';
 is $_->getFloatValue, 73, 'ex>getFloatValue';
 ok !eval{ $_->getStringValue;1}, 'ex->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after ex->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after ex->getStringValue dies';
}

use tests 7; # pixies
for(CSS::DOM::Value::Primitive->new(type => &CSS_PX, value => 73)) {
 test_isa $_, 'pixel value';
 is $_->primitiveType, &CSS_PX, 'pixel->primitiveType';
 is $_->getFloatValue, 73, 'px->getFloatValue';
 ok !eval{ $_->getStringValue;1}, 'pixel->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after pixel->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after pixel->getStringValue dies';
}

use tests 7; # cm
for(CSS::DOM::Value::Primitive->new(type => &CSS_CM, value => 73)) {
 test_isa $_, 'cm value';
 is $_->primitiveType, &CSS_CM, 'cm->primitiveType';
 is $_->getFloatValue, 73, 'cm->getFloatValue';
 ok !eval{ $_->getStringValue;1}, 'cm->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after cm->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after cm->getStringValue dies';
}

use tests 7; # mm
for(CSS::DOM::Value::Primitive->new(type => &CSS_MM, value => 73)) {
 test_isa $_, 'millimetre value';
 is $_->primitiveType, &CSS_MM, 'mm->primitiveType';
 is $_->getFloatValue, 73, 'mm->getFloatValue';
 ok !eval{ $_->getStringValue;1}, 'mm->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after mm->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after mm->getStringValue dies';
}

use tests 7; # inch
for(CSS::DOM::Value::Primitive->new(type => &CSS_IN, value => 73)) {
 test_isa $_, 'inch value';
 is $_->primitiveType, &CSS_IN, 'inch->primitiveType';
 is $_->getFloatValue, 73, 'inch->getFloatValue';
 ok !eval{ $_->getStringValue;1}, 'inch->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after inch->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after inch->getStringValue dies';
}

use tests 7; # points
for(CSS::DOM::Value::Primitive->new(type => &CSS_PT, value => 73)) {
 test_isa $_, 'pointy value';
 is $_->primitiveType, &CSS_PT, 'pointy->primitiveType';
 is $_->getFloatValue, 73, 'pointy->getFloatValue';
 ok !eval{ $_->getStringValue;1}, 'pointy->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after pointy->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after pointy->getStringValue dies';
}

use tests 7; # pica
for(CSS::DOM::Value::Primitive->new(type => &CSS_PC, value => 73)) {
 test_isa $_, 'pica value';
 is $_->primitiveType, &CSS_PC, 'pica->primitiveType';
 is $_->getFloatValue, 73, 'pica->getFloatValue';
 ok !eval{ $_->getStringValue;1}, 'pica->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after pica->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after pica->getStringValue dies';
}

use tests 7; # degrease
for(CSS::DOM::Value::Primitive->new(type => &CSS_DEG, value => 73)) {
 test_isa $_, 'degree value';
 is $_->primitiveType, &CSS_DEG, 'degree->primitiveType';
 is $_->getFloatValue, 73, 'degree->getFloatValue';
 ok !eval{ $_->getStringValue;1}, 'degree->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after degree->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after degree->getStringValue dies';
}

use tests 7; # radians
for(CSS::DOM::Value::Primitive->new(type => &CSS_RAD, value => 73)) {
 test_isa $_, 'radian value';
 is $_->primitiveType, &CSS_RAD, 'radian->primitiveType';
 is $_->getFloatValue, 73, 'radian->getFloatValue';
 ok !eval{ $_->getStringValue;1}, 'radian->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after radian->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after radian->getStringValue dies';
}

use tests 7; # grad
for(CSS::DOM::Value::Primitive->new(type => &CSS_GRAD, value => 73)) {
 test_isa $_, 'grad value';
 is $_->primitiveType, &CSS_GRAD, 'grad->primitiveType';
 is $_->getFloatValue, 73, 'grad->getFloatValue';
 ok !eval{ $_->getStringValue;1}, 'grad->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after grad->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after grad->getStringValue dies';
}

use tests 7; # seconds
for(CSS::DOM::Value::Primitive->new(type => &CSS_S, value => 73)) {
 test_isa $_, 'sec. value';
 is $_->primitiveType, &CSS_S, 'sec.->primitiveType';
 is $_->getFloatValue, 73, 'sec.->getFloatValue';
 ok !eval{ $_->getStringValue;1}, 'sec.->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after sec.->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after sec.->getStringValue dies';
}

use tests 7; # ms
for(CSS::DOM::Value::Primitive->new(type => &CSS_MS, value => 73)) {
 test_isa $_, 'ms value';
 is $_->primitiveType, &CSS_MS, 'ms->primitiveType';
 is $_->getFloatValue, 73, 'ms->getFloatValue';
 ok !eval{ $_->getStringValue;1}, 'ms->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after ms->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after ms->getStringValue dies';
}

use tests 7; # hurts
for(CSS::DOM::Value::Primitive->new(type => &CSS_HZ, value => 73)) {
 test_isa $_, 'hurts value';
 is $_->primitiveType, &CSS_HZ, 'hurts->primitiveType';
 is $_->getFloatValue, 73, 'hurts->getFloatValue';
 ok !eval{ $_->getStringValue;1}, 'hurts->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after hurts->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after hurts->getStringValue dies';
}

use tests 7; # killer hurts
for(CSS::DOM::Value::Primitive->new(type => &CSS_KHZ, value => 73)) {
 test_isa $_, 'killer hurts value';
 is $_->primitiveType, &CSS_KHZ, 'killer hurts->primitiveType';
 is $_->getFloatValue, 73, 'killer hurts->getFloatValue';
 ok !eval{ $_->getStringValue;1}, 'killer hurts->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after killer hurts->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after killer hurts->getStringValue dies';
}

use tests 7; # misc dim
for(
 CSS::DOM::Value::Primitive->new(
  type => &CSS_DIMENSION, value => [73, 'things']
 )
) {
 test_isa $_, 'misc dim value';
 is $_->primitiveType, &CSS_DIMENSION, 'misc dim->primitiveType';
 is $_->getFloatValue, 73, 'misc dim->getFloatValue';
 ok !eval{ $_->getStringValue;1}, 'misc dim->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after misc dim->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after misc dim->getStringValue dies';
}

use tests 7; # string
for(CSS::DOM::Value::Primitive->new(type => &CSS_STRING, value => 73)) {
 test_isa $_, 'string value';
 is $_->primitiveType, &CSS_STRING, 'string->primitiveType';
 ok !eval{ $_->getFloatValue;1}, 'string->getFloatValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after string->getFloatValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after string->getFloatValue dies';
 is $_->getStringValue, 73, 'string->getStringValue';
}

use tests 7; # url
for(CSS::DOM::Value::Primitive->new(type => &CSS_URI, value => 73)) {
 test_isa $_, 'uri value';
 is $_->primitiveType, &CSS_URI, 'uri->primitiveType';
 ok !eval{ $_->getFloatValue;1}, 'uri->getFloatValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after uri->getFloatValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after uri->getFloatValue dies';
 is $_->getStringValue, 73, 'url->getStringValue';
}

use tests 7; # identifier
for(CSS::DOM::Value::Primitive->new(type => &CSS_IDENT, value => 73)) {
 test_isa $_, 'identifier value';
 is $_->primitiveType, &CSS_IDENT, 'identifier->primitiveType';
 ok !eval{ $_->getFloatValue;1}, 'identifier->getFloatValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after identifier->getFloatValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after identifier->getFloatValue dies';
 is $_->getStringValue, 73, 'identifier->getStringValue';
}

use tests 7; # attr
for(CSS::DOM::Value::Primitive->new(type => &CSS_ATTR, value => 73)) {
 test_isa $_, 'attr value';
 is $_->primitiveType, &CSS_ATTR, 'attr->primitiveType';
 ok !eval{ $_->getFloatValue;1}, 'attr->getFloatValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after attr->getFloatValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after attr->getFloatValue dies';
 is $_->getStringValue, 73, 'attr->getStringValue';
}

use tests 9; # counter
for(CSS::DOM::Value::Primitive->new(type => &CSS_COUNTER, value => [73])) {
 test_isa $_, 'counter value';
 is $_->primitiveType, &CSS_COUNTER, 'counter->primitiveType';
 ok !eval{ $_->getFloatValue;1}, 'counter->getFloatValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after counter->getFloatValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after counter->getFloatValue dies';
 ok !eval{ $_->getStringValue;1}, 'counter->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after counter->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after counter->getStringValue dies';
}

use tests 9; # counters
for(CSS::DOM::Value::Primitive->new(
 type => &CSS_COUNTER, value => [73,'breen']
)) {
 test_isa $_, 'counters value';
 is $_->primitiveType, &CSS_COUNTER, 'counters->primitiveType';
 ok !eval{ $_->getFloatValue;1}, 'counters->getFloatValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after counters->getFloatValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after counters->getFloatValue dies';
 ok !eval{ $_->getStringValue;1}, 'counters->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after counters->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after counters->getStringValue dies';
}

use tests 9; # rectangle
for(CSS::DOM::Value::Primitive->new(
 type => &CSS_RECT, value => [
     [type => &CSS_PX, value => 20],
     [type => &CSS_PERCENTAGE, value => 50],
     [type => &CSS_PERCENTAGE, value => 50],
     [type => &CSS_PX, value => 50],
 ]
)) {
 test_isa $_, 'rectangle value';
 is $_->primitiveType, &CSS_RECT, 'rectangle->primitiveType';
 ok !eval{ $_->getFloatValue;1}, 'rectangle->getFloatValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after rectangle->getFloatValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after rectangle->getFloatValue dies';
 ok !eval{ $_->getStringValue;1}, 'rectangle->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after rectangle->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after rectangle->getStringValue dies';
}

use tests 9; #bed colour
for(CSS::DOM::Value::Primitive->new(
 type => &CSS_RGBCOLOR, value => '#bed',
)) {
 test_isa $_, '#bed colour value';
 is $_->primitiveType, &CSS_RGBCOLOR, '#bed colour->primitiveType';
 ok !eval{ $_->getFloatValue;1}, '#bed colour->getFloatValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after #bed colour->getFloatValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after #bed colour->getFloatValue dies';
 ok !eval{ $_->getStringValue;1}, '#bee colour->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after #bee colour->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after #bee colour->getStringValue dies';
}

use tests 9; #c0ffee colour
for(CSS::DOM::Value::Primitive->new(
 type => &CSS_RGBCOLOR, value => '#c0ffee',
)) {
 test_isa $_, '#c0ffee colour value';
 is $_->primitiveType, &CSS_RGBCOLOR, '#c0ffee colour->primitiveType';
 ok !eval{ $_->getFloatValue;1}, '#c0ffee colour->getFloatValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after #c0ffee colour->getFloatValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after #c0ffee colour->getFloatValue dies';
 ok !eval{ $_->getStringValue;1}, '#c0ffee->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after #c0ffee->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after #c0ffee->getStringValue dies';
}

use tests 9; # rgb colour
for(CSS::DOM::Value::Primitive->new(
 type => &CSS_RGBCOLOR, value => [ ([type => &CSS_NUMBER, value => 0])x3 ]
)) {
 test_isa $_, 'rgb value';
 is $_->primitiveType, &CSS_RGBCOLOR, 'rgb->primitiveType';
 ok !eval{ $_->getFloatValue;1}, 'rgb->getFloatValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after rgb->getFloatValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after rgb->getFloatValue dies';
 ok !eval{ $_->getStringValue;1}, 'rgb->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after rgb->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after rgb->getStringValue dies';
}

use tests 9; # rgba colour
for(CSS::DOM::Value::Primitive->new(
 type => &CSS_RGBCOLOR, value => [ ([type => &CSS_NUMBER, value => 0])x4 ]
)) {
 test_isa $_, 'rgba value';
 is $_->primitiveType, &CSS_RGBCOLOR, 'rgba->primitiveType';
 ok !eval{ $_->getFloatValue;1}, 'rgba->getFloatValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after rgba->getFloatValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after rgba->getFloatValue dies';
 ok !eval{ $_->getStringValue;1}, 'rgba->getStringValue dies';
 isa_ok $@, 'CSS::DOM::Exception',
  'class of error after rgba->getStringValue dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
  'error code after rgba->getStringValue dies';
}

# ------------------------------------------
# Tests for setFloatValue and setStringValue

use CSS'DOM'Style;
require CSS::DOM::PropertyParser;
my $s = new CSS'DOM'Style
 property_parser => $CSS::DOM::PropertyParser::Default;

for my $meth ('setFloatValue' ,'setStringValue'){

use tests 6; # read-only properties
 my $v = new CSS::DOM::Value::Primitive
  type => &CSS::DOM::Value::Primitive::CSS_NUMBER, value => 43;
 ok !eval{ $v->$meth(&CSS_IN, 1); 1 },
  qq'calling $meth on an unowned primitive value object dies';
 isa_ok $@, 'CSS::DOM::Exception',
  qq'class of error after primitive->$meth dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::NO_MODIFICATION_ALLOWED_ERR,
  qq'and the right type of error, too (after primitive->$meth dies)';

use tests +26*3*2; # errors for invalid types
 $s->backgroundImage('url(scrat)');
 $v = $s->getPropertyCSSValue('background-image');
 for(qw<UNKNOWN NUMBER PERCENTAGE EMS EXS PX CM MM IN PT PC DEG RAD GRAD MS
        S HZ KHZ DIMENSION STRING IDENT ATTR COUNTER RECT RGBCOLOR>) {
  ok !eval{ $v->$meth(eval"CSS_$_", 1); 1 },
   qq '$meth(CSS_$_) dies when the property does not support it';
  isa_ok $@, 'CSS::DOM::Exception',
   qq'class of error after primitive->$meth(&CSS_$_) dies';
  cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
   qq'and the right type of error, too (after $meth(&CSS_$_) dies)';
 }
 $s->backgroundColor('#bad');
 $v = $s->getPropertyCSSValue('background-color');
 ok !eval{ $v->$meth(&CSS_URI, 1); 1 },
    qq'setFloatValue(CSS_URI) dies when the property does not support it';
 isa_ok $@, 'CSS::DOM::Exception',
        qq'class of error after primitive->$meth(&CSS_URI) dies';
 cmp_ok $@, '==', &CSS::DOM::Exception::INVALID_ACCESS_ERR,
        qq'and the right type of error, too (after $meth(&CSS_URI) dies)';

use tests 4; # retval and CSS_NUMBER
 $s->marginTop('4px');
 is +()=$s->getPropertyCSSValue('margin-top')->$meth(&CSS_NUMBER, 0), 0,
    "$meth returns nothing";
 is $s->marginTop, 0, "successful $meth(CSS_NUMBER)";

use tests 2; # CSS_PERCENTAGE
 $s->height('4px');
 ($v = $s->getPropertyCSSValue('height'))->$meth(&CSS_PERCENTAGE, 50);
 is $s->height, '50%', "successful $meth(CSS_PERCENTAGE)";

use tests 2; # CSS_EMS
 $v->$meth(&CSS_EMS, 50);
 is $s->height, '50em', "successful $meth(CSS_EMS)";

use tests 2; # CSS_EXS
 $v->$meth(&CSS_EXS, 50);
 is $s->height, '50ex', "successful $meth(CSS_EXS)";

use tests 2; # CSS_PX
 $v->$meth(&CSS_PX, 50);
 is $s->height, '50px', "successful $meth(CSS_PX)";

use tests 2; # CSS_CM
 $v->$meth(&CSS_CM, 50);
 is $s->height, '50cm', "successful $meth(CSS_CM)";

use tests 2; # CSS_MM
 $v->$meth(&CSS_MM, 50);
 is $s->height, '50mm', "successful $meth(CSS_MM)";

use tests 2; # CSS_IN
 $v->$meth(&CSS_IN, 50);
 is $s->height, '50in', "successful $meth(CSS_IN)";

use tests 2; # CSS_PT
 $v->$meth(&CSS_PT, 50);
 is $s->height, '50pt', "successful $meth(CSS_PT)";

use tests 2; # CSS_PC
 $v->$meth(&CSS_PC, 50);
 is $s->height, '50pc', "successful $meth(CSS_PC)";

use tests 2; # CSS_DEG
 $s->azimuth('5rad');
 ($v = $s->getPropertyCSSValue('azimuth'))->$meth(&CSS_DEG, 50);
 is $s->azimuth, '50deg', "successful $meth(CSS_DEG)";

use tests 2; # CSS_RAD
 $v->$meth(&CSS_RAD, 50);
 is $s->azimuth, '50rad', "successful $meth(CSS_RAD)";

use tests 2; # CSS_GRAD
 $v->$meth(&CSS_GRAD, 50);
 is $s->azimuth, '50grad', "successful $meth(CSS_GRAD)";

use tests 2; # CSS_MS
 $s->pauseAfter('5s');
 ($v = $s->getPropertyCSSValue('pause-after'))->$meth(&CSS_MS, 50);
 is $s->pauseAfter, '50ms', "successful $meth(CSS_MS)";

use tests 2; # CSS_S
 $v->$meth(&CSS_S, 50);
 is $s->pauseAfter, '50s', "successful $meth(CSS_S)";

use tests 2; # CSS_HZ
 $s->pitch('5khz');
 ($v = $s->getPropertyCSSValue('pitch'))->$meth(&CSS_HZ, 50);
 is lc $s->pitch, '50hz', "successful $meth(CSS_HZ)";

use tests 2; # CSS_KHZ
 $v->$meth(&CSS_KHZ, 30);
 is lc $s->pitch, '30khz', "successful $meth(CSS_KHZ)";

use tests 2; # CSS_STRING
 $s->quotes('"‘" "’"');
 $s->getPropertyCSSValue('quotes')->[0]->$meth(&CSS_STRING, 50);
 like $s->quotes, qr/^(['"])50\1\s+(['"])’\2\z/,
     "successful $meth(CSS_STRING)";

use tests 2; # CSS_URI
 $s->content('""');
 ($v = $s->getPropertyCSSValue('content')->[0])->$meth(&CSS_URI, 50);
 is $s->content, 'url(50)',
     "successful $meth(CSS_URI)";

use tests 2; # CSS_IDENT
 # This test also checks that sub-values of a list do not lose their inter-
 # nal owner attribute when they change type (bug in 0.08 and 0.09).
 $v->$meth(&CSS_IDENT, 'open-quote');
 is $s->content, 'open-quote', "successful $meth(CSS_IDENT)";

use tests 2; # CSS_ATTR
 $v->$meth(&CSS_ATTR, 'open-quote');
 is $s->content, 'attr(open-quote)', "successful $meth(CSS_attr)";

}

__END__ ~~~ I need to finish converting the rest of these tests



 $s->backgroundImage('url(dwow)');
 $v = $s->getPropertyCSSValue('background-image');
 is $v->cssText('none'), 'url(dwow)',
  'setting cssText returns the old value';
 is $s->backgroundImage, 'none',
  'prim_value->cssText("...") sets the owner CSS property';
 is $v->primitiveType, &CSS::DOM::Value::Primitive::CSS_IDENT,
  ' prim->cssText sets the “primitive” type';
 is $v->cssText, 'none',
  ' prim->cssText sets the value object\'s own cssText';

 # We re-use the same value on purpose, to make sure the change in type did
 # not discard the internal owner attribute.
 $v->cssText('inherit');
 is $s->backgroundImage, 'inherit',
  'setting the cssText of a primitive value to inherit changes the prop';
 is $v->cssText, 'inherit',
  'setting the cssText of a prim val to inherit changes its cssText';
 is $v->cssValueType, &CSS_INHERIT,
  'value type after setting a primitive value to inherit';
 isa_ok $v, "CSS::DOM::Value",
  'object class after setting a primitive value to inherit';

 $s->clip('rect(0,0,0,0)');
 $v = $s->getPropertyCSSValue('clip')->top;
 $v->cssText('red');
 is $v->cssText, 0,
  'setting cssText on a sub-value of a rect to a colour does nothing';
 $v->cssText(50);
 is $v->cssText, 0,
  'setting cssText on a rect’s sub-value to a non-zero num does nothing';
 $v->cssText('5px');
 is $v->cssText, '5px',
  'setting cssText on a sub-value of a rect to 5px works';
 is $v->primitiveType, &CSS::DOM::Value::Primitive::CSS_PX,
  'setting cssText on a sub-value of a rect to 5px changes the prim type';
 like $s->clip, qr/^rect\(5px,\s*0,\s*0,\s*0\)\z/,
  'setting cssText on a sub-value of a rect changes the prop that owns it';
 $v->cssText('auto');
 is $v->cssText, 'auto', 'rect sub-values can be set to auto';
 $v->cssText('bdelp');
 is $v->cssText, 'auto', 'but not to any other identifier';

 $s->color('#c0ffee');
 $v = (my $clr = $s->getPropertyCSSValue('color'))->red;
 $v->cssText('red');
 is $v->cssText, 192,
  'setting cssText on a sub-value of a colour to a colour does nothing';
 $v->cssText('255');
 is $v->cssText, '255',
  'setting cssText on a sub-value of a colour to 255 works';
 is $clr->cssText, '#ffffee',
  'changing a colour’s sub-value sets the colour’s cssText';
 $v->cssText('50%');
 is $v->cssText, '50%',
  'setting cssText on a sub-value of a colour to 50% works';
 is $v->primitiveType, &CSS::DOM::Value::Primitive::CSS_PERCENTAGE,
  'changing the cssText of a colour’s sub-value changes the prim type';
 like $clr->cssText, qr/^rgb\(127.5,\s*255,\s*238\)\z/,
  'the colour’s cssText after making the subvalues mixed numbers & %’s';
 $v = $clr->alpha;
 $v->cssText('50%');
 is $v->cssText, 1,
  'alpha values ignore assignments of percentage values to cssText';
 $v->cssText(.5);
 is $v->cssText, .5,
  'but number assignments (to alpha values’ cssText) work';
 like $clr->cssText, qr/^rgba\(127.5,\s*255,\s*238,\s*0.5\)\z/,
  'the colour’s cssText after making the subvalues mixed numbers & %’s';

 $v = $s->getPropertyCSSValue('color');
 $v->cssText('activeborder');;
 is $v->primitiveType, &CSS::DOM::Value::Primitive::CSS_IDENT,
  'setting a colour property’s cssText to a sys. colour makes it an ident';

 $s->backgroundColor('red');
 my $called;
 $s->modification_handler(sub { ++$called });
 $s->getPropertyCSSValue('background-color')->cssText('white');
 is $called, 1,
  "modification_handler is called when a ‘primitive’ value changes";
}


# Methods that still need testing:
# ~~~ getCounterValue getRectValue getRGBColorValue