File: node-literal.t

package info (click to toggle)
librdf-trine-perl 1.019-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,200 kB
  • sloc: perl: 17,601; sql: 20; makefile: 8; sh: 1
file content (65 lines) | stat: -rw-r--r-- 1,520 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env perl
use strict;
use warnings;
no warnings 'redefine';
use URI::file;
use Test::More tests => 30;

use utf8;

use RDF::Trine qw(literal);
use RDF::Trine::Namespace qw(xsd);

ok( literal('0', undef, $xsd->integer)->is_valid_lexical_form, 'integer valid lexical form' );
ok( literal('1', undef, $xsd->integer)->is_valid_lexical_form, 'integer valid lexical form' );
ok( literal('01', undef, $xsd->integer)->is_valid_lexical_form, 'integer valid lexical form' );
ok( not(literal('02 ', undef, $xsd->integer)->is_valid_lexical_form), 'integer valid lexical form' );
ok( not(literal('abc', undef, $xsd->integer)->is_valid_lexical_form), 'integer valid lexical form' );

my %values	= (
	integer	=> {
		'01'	=> '1',
		'+1'	=> '1',
		'-01'	=> '-1',
	},
	decimal	=> {
		'0.00'	=> '0.0',
		'+01.10'	=> '1.1',
	},
	float	=> {
		'-1E4'	=> '-1.0E4',
		'-1e4'	=> '-1.0E4',
		'+1e+01'	=> '1.0E1',
		'1e+000'	=> '1.0E0',
		'-INF'	=> '-INF',
		'+INF'	=> 'INF',
		'NaN'	=> 'NaN',
		'12.78e-2'	=> '1.278E-1',
	},
	double	=> {
		'-1E4'	=> '-1.0E4',
		'-1e4'	=> '-1.0E4',
		'+1e+01'	=> '1.0E1',
		'1e+000'	=> '1.0E0',
		'-INF'	=> '-INF',
		'+INF'	=> 'INF',
		'NaN'	=> 'NaN',
		'12.78e-2'	=> '1.278E-1',
	},
	boolean	=> {
		'true'	=> 'true',
		'1'		=> 'true',
		'false'	=> 'false',
		'0'		=> 'false',
	},
);

foreach my $type (keys %values) {
	while (my($k,$v) = each(%{ $values{$type} })) {
		my $canon	= literal($k, undef, $xsd->$type(), 1);
		is( $canon->literal_value, $v, "canonicalization of xsd:$type" );
	}
}


__END__