forked from davidson16807/relativity.scad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpegs.test.scad
More file actions
68 lines (50 loc) · 2.56 KB
/
pegs.test.scad
File metadata and controls
68 lines (50 loc) · 2.56 KB
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
// testing PEG functions (that used to be in strings.scad)
footest = "foo (1, bar2)";
regex_test = "foooobazfoobarbaz";
echo( "testing contains:" );
assert( contains("foo bar baz", "ba[rz]", regex=true) == true );
assert( contains("foo bar baz", "spam", regex=true) == false );
assert( contains("foo bar baz", "BA[RZ]", ignore_case=true, regex=true ) == true );
assert( contains("foo bar baz", "SPAM", ignore_case=true , regex=true) == false );
echo( "testing index_of:" );
//echo( index_of( ts, "t") );
assert( index_of( ts, "t") == [[0, 1], [10, 11], [13, 14]] );
assert( index_of("foobar foobar", "oo") == [[1,3], [8,10]] );
assert( index_of( mts, "fooBAR") == [] );
//echo( index_of( mts, "test", ignore_case=true) );
assert( index_of( mts, "test", ignore_case=true) == [[10,14]] );
assert( index_of("foo bar baz", "ba[rz]", regex=true) == [[4,7], [8,11]] );
assert( index_of("foo bar baz", "BA[RZ]", regex=true, ignore_case=true) == [[4,7], [8,11]] );
assert( index_of("", "x") == [] );
echo( "testing grep:" );
assert( grep("foo bar baz", "ba[rz]") == ["bar", "baz"] );
assert( grep("foo bar baz", "BA[RZ]") == [] );
assert( grep("foo 867-5309 baz", "\\d\\d\\d-?\\d\\d\\d\\d") == ["867-5309"] );
assert( grep("foo bar baz", "BA[RZ]", ignore_case=true) == ["bar", "baz"] );
echo( "testing replace:" );
assert( replace( "foobar", "oo", "ee") == "feebar" );
assert( replace( "foobar foobar", "oo", "ee") == "feebar feebar" );
assert( replace( "foobar", "OO", "ee", ignore_case=true) == "feebar" );
assert( replace( "foobar foobar", "OO", "ee", ignore_case=true) == "feebar feebar" );
assert( replace( "foo bar baz", "ba[rz]", "boo", regex=true) == "foo boo boo" );
assert( replace( "foo bar baz", "BA[RZ]", "spam", regex=true, ignore_case=true) == "foo spam spam" );
echo( "testing split:" );
//echo( split( "" ) );
assert( split("") == [] );
//echo( "index ", index_of( ts, " ", true ) );
//echo( "index ", index_of( ts, " ", false ) );
//echo( "split ts ", split(ts, " ") );
assert( split(ts, " ") );
cts = ",a string, with, commas,";
//echo( str( "with commas ", cts ) );
//echo( split(cts) );
assert( split(cts) == split(cts, " " ) );
assert( split(cts) == [ ",a", "string,", "with,", "commas," ]);
//echo( split(cts, "," ) );
assert( split(cts, ",") == [ "a string", " with", " commas" ] );
//assert( split(regex_test, "fo+", regex=true) );
//assert( split("bazfoobar", "fo+", regex=true) );
//assert( split("", "fo+", regex=true) );
//assert( split("", "fo+", regex=true) );
//assert( split(regex_test, "FO+", regex=true, ignore_case=true) == ["baz", "barbaz"] );
echo ( "all done" );