joker 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,131 @@
1
+ #include <stdarg.h>
2
+ #include <stddef.h>
3
+ #include <stdbool.h>
4
+ #include <setjmp.h>
5
+ #include <cmockery.h>
6
+ #include <stdio.h>
7
+ #include <string.h>
8
+ #include <ruby.h>
9
+ #include "compile.h"
10
+ #include "Wildcard.h"
11
+
12
+ //
13
+ // Possible scenarios:
14
+ // * empty
15
+ // not empty
16
+ // * contains group
17
+ // contains fixed
18
+ // contains wildcard
19
+ // contains kleene
20
+ // * casefold
21
+ // not casefold
22
+ //
23
+
24
+
25
+ static void generic_test(wildcard_string, cstring, casefold, should_match) // {{{1
26
+ const char * wildcard_string;
27
+ const char * cstring;
28
+ bool casefold;
29
+ bool should_match;
30
+ {
31
+ Wildcard * wildcard;
32
+ bool matches;
33
+
34
+ wildcard = Wildcard_compile(wildcard_string, strlen(wildcard_string));
35
+ matches = Wildcard_match(wildcard, cstring, strlen(cstring), casefold);
36
+ assert_int_equal((int)should_match, (int)matches);
37
+
38
+ Wildcard_free(wildcard);
39
+ }
40
+
41
+
42
+ static void test_empty(state) // {{{1
43
+ void ** state;
44
+ {
45
+ generic_test("", "", false, true);
46
+ generic_test("", "", true, true);
47
+ generic_test("", "a", false, false);
48
+ generic_test("", "a", true, false);
49
+ }
50
+
51
+
52
+ static void test_fixed(state) // {{{1
53
+ void ** state;
54
+ {
55
+ generic_test("uiae", "uiae", false, true);
56
+ generic_test("uiae", "UIAE", true, true);
57
+ generic_test("uiae", "UIAE", false, false); // bad case
58
+ generic_test("uiae", "", false, false); // empty
59
+ generic_test("uiae", "u", false, false); // too short
60
+ generic_test("uiae", "uiaeo", false, false); // too long
61
+ }
62
+
63
+
64
+ static void test_group(state) // {{{1
65
+ void ** state;
66
+ {
67
+ generic_test("[uiae]", "u", false, true);
68
+ generic_test("[uiae]", "U", true, true);
69
+ generic_test("[uiae]", "U", false, false); // bad case
70
+ generic_test("[uiae]", "", false, false); // empty
71
+ generic_test("[uiae]", "o", false, false); // wrong character
72
+ generic_test("[uiae]", "ui", false, false); // too long
73
+ }
74
+
75
+
76
+ static void test_wild(state) // {{{1
77
+ void ** state;
78
+ {
79
+ generic_test("?", "u", false, true);
80
+ generic_test("?", "U", true, true);
81
+ generic_test("?", "", false, false); // empty
82
+ generic_test("?", "ui", false, false); // too long
83
+ generic_test("u?", "u", false, false); // too short
84
+ generic_test("??", "u", false, false); // too short
85
+ }
86
+
87
+
88
+ static void test_kleene(state) // {{{1
89
+ void ** state;
90
+ {
91
+ generic_test("*", "uiae", false, true);
92
+ generic_test("*", "UIAE", true, true);
93
+ generic_test("*", "", false, true); // empty
94
+ generic_test("*u", "uiae", false, false); // too short
95
+ generic_test("*?*", "", false, false); // too short
96
+ }
97
+
98
+
99
+ static void test_mixed(state) //{{{1
100
+ void ** state;
101
+ {
102
+ generic_test("_*_", "__", false, true);
103
+ generic_test("_*_", "_uiae_", false, true);
104
+ generic_test("_*_", "_uiae_", false, true);
105
+ generic_test("_*_", "u_ia_e", false, false);
106
+ generic_test("_*_", "uiae_", false, false);
107
+ generic_test("_*_", "_uiae", false, false);
108
+ generic_test("_*_", "", false, false);
109
+
110
+ generic_test("*_*", "_", false, true);
111
+ generic_test("*_*", "uiae_", false, true);
112
+ generic_test("*_*", "_uiae", false, true);
113
+ generic_test("*_*", "ui_ae", false, true);
114
+ generic_test("*_*", "_____", false, true);
115
+ generic_test("*_*", "uiae", false, false);
116
+ generic_test("*_*", "", false, false);
117
+ }
118
+
119
+
120
+ int main() { // {{{1
121
+ const UnitTest tests[] = {
122
+ unit_test(test_empty),
123
+ unit_test(test_fixed),
124
+ unit_test(test_group),
125
+ unit_test(test_wild),
126
+ unit_test(test_kleene),
127
+ unit_test(test_mixed),
128
+ };
129
+ return run_tests(tests);
130
+ }
131
+
@@ -9,18 +9,6 @@ describe 'A Wildcard' do
9
9
  @wildc ||= Wildcard['Fairy[cf]ake[!\\]]']
10
10
  end
11
11
 
12
- it 'should be constructed correctly' do
13
- @wild.casefold?.should.be.false
14
- @wildi.casefold?.should.be.true
15
- @wildc.casefold?.should.be.false
16
- regexp = @wild.instance_variable_get(:@regexp)
17
- regexpi = @wildi.instance_variable_get(:@regexp)
18
- regexpc = @wildc.instance_variable_get(:@regexp)
19
- regexp.should.be == /^Fairy.ake.*$/
20
- regexpi.should.be == /^Fairy.ake.*\?$/i
21
- regexpc.should.be == /^Fairy[cf]ake[!\]]$/
22
- end
23
-
24
12
  it 'should match correct strings' do
25
13
  @wild.should =~ 'Fairycake'
26
14
  @wild.should =~ 'Fairyfakes'
@@ -39,12 +27,6 @@ describe 'A Wildcard' do
39
27
  @wildi.should =~ 'FairyLake IS A COOL Place?'
40
28
  end
41
29
 
42
- it 'should handle escapes correctly' do
43
- wild = Wildcard['\\\\a\\?b\\*c\\d.][+'] # \\a\?b\*c\d.][+
44
- regexp = wild.instance_variable_get(:@regexp)
45
- regexp.should.be == /^\\a\?b\*c\\d\.\]\[\+$/
46
- end
47
-
48
30
  it 'should quote correctly' do
49
31
  Wildcard.quote('*?\\').should.be == '\\*\\?\\\\' # *?\ --> \*\?\\
50
32
  Wildcard.quote('\\\\').should.be == '\\\\\\\\' # \\ --> \\\\
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: joker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabian Streitel
@@ -28,8 +28,24 @@ files:
28
28
  - README.markdown
29
29
  - Rakefile
30
30
  - VERSION
31
+ - ext/joker_native/Joker.c
32
+ - ext/joker_native/Joker.h
33
+ - ext/joker_native/Wildcard.c
34
+ - ext/joker_native/Wildcard.h
35
+ - ext/joker_native/compile.c
36
+ - ext/joker_native/compile.h
37
+ - ext/joker_native/extconf.rb
38
+ - ext/joker_native/match.c
39
+ - ext/joker_native/match.h
31
40
  - lib/joker.rb
32
- - test/test_joker.rb
41
+ - tasks/c_extensions.rake
42
+ - tasks/jeweler.rake
43
+ - tasks/rdoc.rake
44
+ - tasks/shortcuts.rake
45
+ - tasks/test.rake
46
+ - test/c/test_compile.c
47
+ - test/c/test_match.c
48
+ - test/ruby/test_joker.rb
33
49
  has_rdoc: true
34
50
  homepage: http://karottenreibe.github.com/joker
35
51
  licenses: []
@@ -59,4 +75,4 @@ signing_key:
59
75
  specification_version: 3
60
76
  summary: Joker is a simple wildcard implementation that works much like Regexps
61
77
  test_files:
62
- - test/test_joker.rb
78
+ - test/ruby/test_joker.rb