source: josm/trunk/data/validator/numeric.mapcss@ 6532

Last change on this file since 6532 was 6532, checked in by Don-vip, 10 years ago

fix #8687, see #9414, see #9470 - tagchecker: update numeric tests to new MapCSS format, with embedded unit tests. MapCSS syntax updated a bit for regex.

File size: 5.1 KB
Line 
1/* measurement values and units warnings (ticket #8687) */
2
3*[layer =~ /\+.*/] {
4 throwWarning: tr("layer tag with + sign");
5 assertMatch: "node layer=+1";
6 assertNoMatch: "node layer=1";
7 assertNoMatch: "node layer=-1";
8}
9
10*[layer !~ /^0$|^(-|\+)?[1-5]$/] {
11 throwWarning: tr("layer should be between -5 and 5");
12 assertMatch: "node layer=-50";
13 assertMatch: "node layer=6";
14 assertMatch: "node layer=+100";
15 assertNoMatch: "node layer=-5";
16 assertNoMatch: "node layer=0";
17 assertNoMatch: "node layer=2";
18 assertNoMatch: "node layer=+5";
19}
20
21*[level !~ /^((([0-9]|-[1-9])|[1-9][0-9]*)(\.5)?)(;(([0-9]|-[1-9])|[1-9][0-9]*)(\.5)?)*$|^-0\.5$/] {
22 throwWarning: tr("level should be numbers with optional .5 increments");
23 assertMatch: "node level=one";
24 assertNoMatch: "node level=0";
25 assertNoMatch: "node level=1";
26 assertNoMatch: "node level=-1";
27 assertNoMatch: "node level=-0.5";
28 assertNoMatch: "node level=1.5";
29}
30
31*[height !~ /^(([0-9]+\.?[0-9]*( (m|ft))?)|([1-9][0-9]*\'((10|11|[0-9])((\.[0-9]+)?)\")?))$/] {
32 throwWarning: tr("{0}: meters is default; period is separator; if units, put space then unit", "height");
33 assertMatch: "node height=medium";
34 assertMatch: "node height=-5";
35 assertNoMatch: "node height=2 m";
36 assertNoMatch: "node height=5";
37 assertNoMatch: "node height=7.8";
38 assertNoMatch: "node height=20 ft";
39 assertNoMatch: "node height=22'";
40}
41
42*[maxheight !~ /^(([1-9][0-9]*(\.[0-9]+)?( (m|ft))?)|([0-9]+\'(([0-9]|10|11)(\.[0-9]*)?\")?))$/] {
43 throwWarning: tr("{0}: meters is default; period is separator; if units, put space then unit", "maxheight");
44 assertMatch: "node maxheight=something";
45 assertMatch: "node maxheight=-5";
46 assertMatch: "node maxheight=0";
47 assertNoMatch: "node maxheight=4";
48 assertNoMatch: "node maxheight=3.5";
49 assertNoMatch: "node maxheight=2 m";
50 assertNoMatch: "node maxheight=14 ft";
51 assertNoMatch: "node maxheight=10'";
52 assertNoMatch: "node maxheight=16'3\"";
53}
54
55way[width !~ /^(([0-9]+\.?[0-9]*( [a-z]+)?)|([0-9]+\'([0-9]+\.?[0-9]*\")?))$/] {
56 throwWarning: tr("{0}: meters is default; period is separator; if units, put space then unit", "width");
57 assertMatch: "way width=something";
58 assertMatch: "way width=-5";
59 assertNoMatch: "way width=3";
60 assertNoMatch: "way width=0.5";
61 assertNoMatch: "way width=1 m";
62 assertNoMatch: "way width=10 ft";
63 assertNoMatch: "way width=1'";
64 assertNoMatch: "way width=10'5\"";
65}
66
67*[maxwidth !~ /^(([0-9]+\.?[0-9]*( (m|ft))?)|([0-9]+\'[0-9]+\.?[0-9]*\"))$/] {
68 throwWarning: tr("{0}: meters is default; period is separator; if units, put space then unit", "maxwidth");
69 assertMatch: "way maxwidth=something";
70 assertMatch: "way maxwidth=-5";
71 assertNoMatch: "way maxwidth=2";
72 assertNoMatch: "way maxwidth=6'6\"";
73 assertNoMatch: "way maxwidth=2.5";
74 assertNoMatch: "way maxwidth=7 ft";
75}
76
77way[maxspeed !~ /^(signals|none|unposted|unknown|variable|walk|[1-9][0-9]*( [a-z]+)?|[A-Z][A-Z]:(urban|rural|living_street|motorway))$/] {
78 throwWarning: tr("unusual {0} format", "maxspeed");
79 assertMatch: "way maxspeed=something";
80 assertMatch: "way maxspeed=-50";
81 assertMatch: "way maxspeed=0";
82 assertNoMatch: "way maxspeed=50";
83 assertNoMatch: "way maxspeed=30 mph";
84 assertNoMatch: "way maxspeed=RO:urban";
85 assertNoMatch: "way maxspeed=RU:rural";
86 assertNoMatch: "way maxspeed=RU:living_street";
87 assertNoMatch: "way maxspeed=DE:motorway";
88 assertNoMatch: "way maxspeed=signals";
89 assertNoMatch: "way maxspeed=none";
90 assertNoMatch: "way maxspeed=variable";
91}
92
93way[voltage =~ /(.*[A-Za-z].*)|.*,.*|.*( ).*/] {
94 throwWarning: tr("voltage should be in volts with no units/delimiter/spaces");
95 assertMatch: "way voltage=medium";
96 assertNoMatch: "way voltage=15000";
97}
98
99/* some users are using frequency for other purposes (not electromagnetic)
100 with the values 'perennial' and 'intermittent'; the vast majority are 0, 16.7, 50 and 60 */
101way[frequency !~ /^(0|[1-9][0-9]*(\.[0-9]+)?)( (kHz|MHz|GHz|THz))?$/] {
102 throwWarning: tr("unusual {0} specification", "frequency");
103 assertMatch: "way frequency=something";
104 assertNoMatch: "way frequency=0"; /* DC */
105 assertNoMatch: "way frequency=16.7";
106 assertNoMatch: "way frequency=50";
107 assertNoMatch: "way frequency=680 kHz";
108 assertNoMatch: "way frequency=123.5 MHz";
109}
110
111way[gauge !~ /^([1-9][0-9]{1,3}(;[1-9][0-9]{1,3})*|broad|standard|narrow)$/] {
112 throwWarning: tr("unusual train track gauge; use mm with no separator");
113 assertMatch: "way gauge=something";
114 assertNoMatch: "way gauge=1435";
115 assertNoMatch: "way gauge=1000;1435";
116 assertNoMatch: "way gauge=standard";
117 assertNoMatch: "way gauge=narrow";
118}
119
120/* the numbers for percentage and degrees include could probably be bracketed a bit more precisely */
121way[incline !~ /^(up|down|-?([0-9]+?(\.[1-9]%)?|100)[%°]?)$/] {
122 throwWarning: tr("unusual incline; use percentages/degrees or up/down");
123 assertMatch: "way incline=extreme";
124 assertNoMatch: "way incline=up";
125 assertNoMatch: "way incline=down";
126 assertNoMatch: "way incline=10%";
127 assertNoMatch: "way incline=-5%";
128 assertNoMatch: "way incline=10°";
129}
Note: See TracBrowser for help on using the repository browser.