File: 02-structure.t

package info (click to toggle)
libregexp-pattern-license-perl 3.11.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,580 kB
  • sloc: perl: 12,506; makefile: 2; sh: 1
file content (64 lines) | stat: -rw-r--r-- 1,479 bytes parent folder | download | duplicates (2)
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
use Test2::V0;

use Regexp::Pattern::License;

#plan 11;

my %RE = %Regexp::Pattern::License::RE;

my $property  = '_?[a-z][a-z0-9_]*';
my $attribute = '[a-z][a-z0-9_]*';
my $lang      = '[a-z]{2,3}(?:_[A-Z]{2,3})?';

my $localspec_re = qr/^(?:
	# metadata and Regexp::Pattern structs without attributes
	description|examples|licenseversion|tags|gen|gen_args
|
	(?:
		# metadata with optional properties
		(?:name|caption|summary|iri)
		(?:\.alt(?:\.(?:
			# TODO: add tests to check each org
			# TODO: maybe drop less popular orgs (instead using misc)
			org\.(?:cc|debian|fedora|fsf|gentoo|linfo|osi|perl|scancode|spdx|steward|tldr|trove|wikipedia|wikidata)
		|
			(?:since|until)\.(?:date_\d{8})
		|
			archive\.(?:time_\d{14})
		|
			synth\.nogrant
		|
			(?:lang\.$lang)?
		|
			(?:old|path|legal|iri|format|misc)\.$attribute
		))+)?
	|
		# patterns
		_?pat
		(?:\.alt(?:\.(?:
			subject\.(?:name|grant|license|iri|trait)
		|
			# TODO: drop overlapping terms
			# TODO: add line_or_sentence, and require unigueness
			scope\.(?:line|sentence|paragraph|multiparagraph|section|multisection|all)
		|
			(?:lang\.$lang)?
		|
			(?:target|part|type|synth|misc)\.$attribute
		))+)?
	)
)$/x;

like \%RE, hash {
	all_keys match qr/^$property(?:\.$attribute)*$/
}, 'object names match Regexp::Pattern spec';

like \%RE, hash {
	all_vals hash {

		all_keys match $localspec_re;
	}
},
	'properties match Regexp::Pattern spec and attributes are alt + key/value pairs';

done_testing;