fear 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -60
- data/.travis.yml +8 -4
- data/CHANGELOG.md +7 -1
- data/Gemfile +5 -3
- data/Gemfile.lock +18 -20
- data/README.md +28 -14
- data/Rakefile +61 -60
- data/examples/pattern_extracting.rb +8 -6
- data/examples/pattern_matching_binary_tree_set.rb +4 -2
- data/examples/pattern_matching_number_in_words.rb +46 -42
- data/fear.gemspec +29 -27
- data/lib/fear.rb +44 -37
- data/lib/fear/await.rb +33 -0
- data/lib/fear/awaitable.rb +28 -0
- data/lib/fear/either.rb +2 -0
- data/lib/fear/either_api.rb +2 -0
- data/lib/fear/either_pattern_match.rb +2 -0
- data/lib/fear/empty_partial_function.rb +3 -1
- data/lib/fear/extractor.rb +30 -28
- data/lib/fear/extractor/anonymous_array_splat_matcher.rb +2 -0
- data/lib/fear/extractor/any_matcher.rb +2 -0
- data/lib/fear/extractor/array_head_matcher.rb +2 -0
- data/lib/fear/extractor/array_matcher.rb +2 -0
- data/lib/fear/extractor/array_splat_matcher.rb +2 -0
- data/lib/fear/extractor/empty_list_matcher.rb +2 -0
- data/lib/fear/extractor/extractor_matcher.rb +5 -3
- data/lib/fear/extractor/grammar.rb +5 -3
- data/lib/fear/extractor/identifier_matcher.rb +2 -0
- data/lib/fear/extractor/matcher.rb +5 -3
- data/lib/fear/extractor/matcher/and.rb +3 -1
- data/lib/fear/extractor/named_array_splat_matcher.rb +2 -0
- data/lib/fear/extractor/pattern.rb +7 -5
- data/lib/fear/extractor/typed_identifier_matcher.rb +2 -0
- data/lib/fear/extractor/value_matcher.rb +2 -0
- data/lib/fear/extractor_api.rb +2 -0
- data/lib/fear/failure.rb +2 -0
- data/lib/fear/failure_pattern_match.rb +2 -0
- data/lib/fear/for.rb +4 -2
- data/lib/fear/for_api.rb +3 -1
- data/lib/fear/future.rb +141 -64
- data/lib/fear/future_api.rb +2 -0
- data/lib/fear/left.rb +3 -1
- data/lib/fear/left_pattern_match.rb +2 -0
- data/lib/fear/none.rb +4 -2
- data/lib/fear/none_pattern_match.rb +2 -0
- data/lib/fear/option.rb +3 -1
- data/lib/fear/option_api.rb +2 -0
- data/lib/fear/option_pattern_match.rb +2 -0
- data/lib/fear/partial_function.rb +10 -8
- data/lib/fear/partial_function/and_then.rb +4 -2
- data/lib/fear/partial_function/any.rb +2 -0
- data/lib/fear/partial_function/combined.rb +3 -1
- data/lib/fear/partial_function/empty.rb +2 -0
- data/lib/fear/partial_function/guard.rb +7 -5
- data/lib/fear/partial_function/guard/and.rb +2 -0
- data/lib/fear/partial_function/guard/and3.rb +2 -0
- data/lib/fear/partial_function/guard/or.rb +2 -0
- data/lib/fear/partial_function/lifted.rb +2 -0
- data/lib/fear/partial_function/or_else.rb +3 -1
- data/lib/fear/partial_function_class.rb +3 -1
- data/lib/fear/pattern_match.rb +3 -1
- data/lib/fear/pattern_matching_api.rb +3 -1
- data/lib/fear/promise.rb +11 -3
- data/lib/fear/right.rb +3 -1
- data/lib/fear/right_biased.rb +4 -2
- data/lib/fear/right_pattern_match.rb +2 -0
- data/lib/fear/some.rb +2 -0
- data/lib/fear/some_pattern_match.rb +2 -0
- data/lib/fear/struct.rb +235 -0
- data/lib/fear/success.rb +2 -0
- data/lib/fear/success_pattern_match.rb +2 -0
- data/lib/fear/try.rb +2 -0
- data/lib/fear/try_api.rb +2 -0
- data/lib/fear/try_pattern_match.rb +2 -0
- data/lib/fear/unit.rb +6 -2
- data/lib/fear/utils.rb +4 -2
- data/lib/fear/version.rb +4 -1
- data/spec/fear/done_spec.rb +7 -5
- data/spec/fear/either/mixin_spec.rb +4 -2
- data/spec/fear/either_pattern_match_spec.rb +10 -8
- data/spec/fear/extractor/array_matcher_spec.rb +65 -63
- data/spec/fear/extractor/extractor_matcher_spec.rb +64 -62
- data/spec/fear/extractor/grammar_array_spec.rb +5 -3
- data/spec/fear/extractor/identified_matcher_spec.rb +18 -16
- data/spec/fear/extractor/identifier_matcher_spec.rb +26 -24
- data/spec/fear/extractor/pattern_spec.rb +17 -15
- data/spec/fear/extractor/typed_identifier_matcher_spec.rb +23 -21
- data/spec/fear/extractor/value_matcher_number_spec.rb +29 -27
- data/spec/fear/extractor/value_matcher_string_spec.rb +27 -25
- data/spec/fear/extractor/value_matcher_symbol_spec.rb +24 -22
- data/spec/fear/extractor_api_spec.rb +70 -68
- data/spec/fear/extractor_spec.rb +23 -21
- data/spec/fear/failure_spec.rb +59 -57
- data/spec/fear/for_spec.rb +19 -17
- data/spec/fear/future_spec.rb +456 -240
- data/spec/fear/guard_spec.rb +26 -24
- data/spec/fear/left_spec.rb +60 -58
- data/spec/fear/none_spec.rb +36 -34
- data/spec/fear/option/mixin_spec.rb +9 -7
- data/spec/fear/option_pattern_match_spec.rb +10 -8
- data/spec/fear/partial_function/empty_spec.rb +12 -10
- data/spec/fear/partial_function_and_then_spec.rb +39 -37
- data/spec/fear/partial_function_composition_spec.rb +46 -44
- data/spec/fear/partial_function_or_else_spec.rb +92 -90
- data/spec/fear/partial_function_spec.rb +46 -44
- data/spec/fear/pattern_match_spec.rb +31 -29
- data/spec/fear/promise_spec.rb +19 -17
- data/spec/fear/right_biased/left.rb +28 -26
- data/spec/fear/right_biased/right.rb +51 -49
- data/spec/fear/right_spec.rb +58 -56
- data/spec/fear/some_spec.rb +30 -28
- data/spec/fear/success_spec.rb +50 -48
- data/spec/fear/try/mixin_spec.rb +5 -3
- data/spec/fear/try_pattern_match_spec.rb +10 -8
- data/spec/fear/utils_spec.rb +16 -14
- data/spec/spec_helper.rb +7 -5
- data/spec/struct_spec.rb +226 -0
- metadata +18 -13
@@ -1,76 +1,78 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Fear::Extractor::ValueMatcher, "Number" do
|
2
4
|
let(:parser) { Fear::Extractor::GrammarParser.new }
|
3
5
|
let(:matcher) { parser.parse(pattern).to_matcher }
|
4
6
|
|
5
|
-
describe
|
7
|
+
describe "#defined_at?" do
|
6
8
|
subject { matcher }
|
7
9
|
|
8
|
-
context
|
9
|
-
let(:pattern) {
|
10
|
+
context "Integer" do
|
11
|
+
let(:pattern) { "1" }
|
10
12
|
|
11
13
|
it { is_expected.to be_defined_at(1) }
|
12
14
|
it { is_expected.to be_defined_at(1.0) }
|
13
15
|
it { is_expected.not_to be_defined_at(2) }
|
14
|
-
it { is_expected.not_to be_defined_at(
|
16
|
+
it { is_expected.not_to be_defined_at("1") }
|
15
17
|
end
|
16
18
|
|
17
|
-
context
|
18
|
-
context
|
19
|
-
let(:pattern) {
|
19
|
+
context "Float" do
|
20
|
+
context "against float" do
|
21
|
+
let(:pattern) { "1.2" }
|
20
22
|
|
21
23
|
it { is_expected.to be_defined_at(1.2) }
|
22
24
|
it { is_expected.not_to be_defined_at(1.3) }
|
23
25
|
end
|
24
26
|
|
25
|
-
context
|
26
|
-
let(:pattern) {
|
27
|
+
context "against integer" do
|
28
|
+
let(:pattern) { "1.0" }
|
27
29
|
|
28
30
|
it { is_expected.to be_defined_at(1) }
|
29
31
|
it { is_expected.not_to be_defined_at(2) }
|
30
|
-
it { is_expected.not_to be_defined_at(
|
32
|
+
it { is_expected.not_to be_defined_at("1") }
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
35
|
-
describe
|
36
|
-
subject { matcher.
|
37
|
+
describe "#call" do
|
38
|
+
subject { matcher.(other) }
|
37
39
|
|
38
|
-
let(:pattern) {
|
40
|
+
let(:pattern) { "1.0" }
|
39
41
|
|
40
|
-
context
|
42
|
+
context "defined" do
|
41
43
|
let(:other) { 1 }
|
42
44
|
|
43
45
|
it { is_expected.to eq({}) }
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
47
|
-
describe
|
49
|
+
describe "#failure_reason" do
|
48
50
|
subject { matcher.failure_reason(other) }
|
49
51
|
|
50
|
-
let(:pattern) {
|
52
|
+
let(:pattern) { "1.0" }
|
51
53
|
|
52
|
-
context
|
54
|
+
context "match integer" do
|
53
55
|
let(:other) { 1 }
|
54
|
-
let(:pattern) {
|
56
|
+
let(:pattern) { "1" }
|
55
57
|
|
56
58
|
it { is_expected.to eq(Fear.none) }
|
57
59
|
end
|
58
60
|
|
59
|
-
context
|
61
|
+
context "match float" do
|
60
62
|
let(:other) { 1.0 }
|
61
|
-
let(:pattern) {
|
63
|
+
let(:pattern) { "1" }
|
62
64
|
|
63
65
|
it { is_expected.to eq(Fear.none) }
|
64
66
|
end
|
65
67
|
|
66
|
-
context
|
68
|
+
context "does not match another integer" do
|
67
69
|
let(:other) { 2 }
|
68
|
-
let(:pattern) {
|
70
|
+
let(:pattern) { "1" }
|
69
71
|
|
70
|
-
it { is_expected.to eq(Fear.some(
|
71
|
-
Expected `2` to match:
|
72
|
-
1
|
73
|
-
^
|
72
|
+
it { is_expected.to eq(Fear.some(<<~ERROR.strip)) }
|
73
|
+
Expected `2` to match:
|
74
|
+
1
|
75
|
+
^
|
74
76
|
ERROR
|
75
77
|
end
|
76
78
|
end
|
@@ -1,25 +1,27 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Fear::Extractor::ValueMatcher, "String" do
|
2
4
|
let(:parser) { Fear::Extractor::GrammarParser.new }
|
3
5
|
let(:matcher) { parser.parse(pattern).to_matcher }
|
4
6
|
|
5
|
-
describe
|
7
|
+
describe "#defined_at?" do
|
6
8
|
subject { matcher }
|
7
9
|
|
8
|
-
context
|
10
|
+
context "double quotas" do
|
9
11
|
let(:pattern) { %("foo") }
|
10
12
|
|
11
|
-
it { is_expected.to be_defined_at(
|
12
|
-
it { is_expected.not_to be_defined_at(
|
13
|
+
it { is_expected.to be_defined_at("foo") }
|
14
|
+
it { is_expected.not_to be_defined_at("boo") }
|
13
15
|
it { is_expected.not_to be_defined_at(2) }
|
14
16
|
|
15
|
-
context
|
17
|
+
context "single quotes inside" do
|
16
18
|
let(:pattern) { %("f'o'o") }
|
17
19
|
|
18
20
|
it { is_expected.to be_defined_at(%(f'o'o)) }
|
19
21
|
it { is_expected.not_to be_defined_at(%(f"o"o)) }
|
20
22
|
end
|
21
23
|
|
22
|
-
context
|
24
|
+
context "escaped double quotes inside" do
|
23
25
|
let(:pattern) { '"f\"oo"' }
|
24
26
|
|
25
27
|
it { is_expected.to be_defined_at('f"oo') }
|
@@ -27,21 +29,21 @@ RSpec.describe Fear::Extractor::ValueMatcher, 'String' do
|
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
30
|
-
context
|
32
|
+
context "single quotas" do
|
31
33
|
let(:pattern) { %('foo') }
|
32
34
|
|
33
|
-
it { is_expected.to be_defined_at(
|
34
|
-
it { is_expected.not_to be_defined_at(
|
35
|
+
it { is_expected.to be_defined_at("foo") }
|
36
|
+
it { is_expected.not_to be_defined_at("boo") }
|
35
37
|
it { is_expected.not_to be_defined_at(2) }
|
36
38
|
|
37
|
-
context
|
39
|
+
context "double quotes inside" do
|
38
40
|
let(:pattern) { %('f"o"o') }
|
39
41
|
|
40
42
|
it { is_expected.to be_defined_at(%(f"o"o)) }
|
41
43
|
it { is_expected.not_to be_defined_at(%(f'o'o)) }
|
42
44
|
end
|
43
45
|
|
44
|
-
context
|
46
|
+
context "escaped single quotes inside" do
|
45
47
|
let(:pattern) { "'f\\'oo'" }
|
46
48
|
|
47
49
|
it { is_expected.to be_defined_at("f\\'oo") }
|
@@ -50,36 +52,36 @@ RSpec.describe Fear::Extractor::ValueMatcher, 'String' do
|
|
50
52
|
end
|
51
53
|
end
|
52
54
|
|
53
|
-
describe
|
54
|
-
subject { matcher.
|
55
|
+
describe "#call" do
|
56
|
+
subject { matcher.(other) }
|
55
57
|
|
56
58
|
let(:pattern) { '"foo"' }
|
57
59
|
|
58
|
-
context
|
59
|
-
let(:other) {
|
60
|
+
context "defined" do
|
61
|
+
let(:other) { "foo" }
|
60
62
|
|
61
63
|
it { is_expected.to eq({}) }
|
62
64
|
end
|
63
65
|
end
|
64
66
|
|
65
|
-
describe
|
67
|
+
describe "#failure_reason" do
|
66
68
|
subject { matcher.failure_reason(other) }
|
67
69
|
|
68
|
-
context
|
69
|
-
let(:other) {
|
70
|
+
context "match" do
|
71
|
+
let(:other) { "foo" }
|
70
72
|
let(:pattern) { '"foo"' }
|
71
73
|
|
72
74
|
it { is_expected.to eq(Fear.none) }
|
73
75
|
end
|
74
76
|
|
75
|
-
context
|
76
|
-
let(:other) {
|
77
|
+
context "does not match" do
|
78
|
+
let(:other) { "bar" }
|
77
79
|
let(:pattern) { '"foo"' }
|
78
80
|
|
79
|
-
it { is_expected.to eq(Fear.some(
|
80
|
-
Expected `"bar"` to match:
|
81
|
-
"foo"
|
82
|
-
^
|
81
|
+
it { is_expected.to eq(Fear.some(<<~ERROR.strip)) }
|
82
|
+
Expected `"bar"` to match:
|
83
|
+
"foo"
|
84
|
+
^
|
83
85
|
ERROR
|
84
86
|
end
|
85
87
|
end
|
@@ -1,68 +1,70 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Fear::Extractor::ValueMatcher, "Symbol" do
|
2
4
|
let(:parser) { Fear::Extractor::GrammarParser.new }
|
3
5
|
let(:matcher) { parser.parse(pattern).to_matcher }
|
4
6
|
|
5
|
-
describe
|
7
|
+
describe "#defined_at?" do
|
6
8
|
subject { matcher }
|
7
9
|
|
8
|
-
context
|
9
|
-
let(:pattern) {
|
10
|
+
context "no quotas" do
|
11
|
+
let(:pattern) { ":foo" }
|
10
12
|
|
11
13
|
it { is_expected.to be_defined_at(:foo) }
|
12
|
-
it { is_expected.not_to be_defined_at(
|
14
|
+
it { is_expected.not_to be_defined_at("foo") }
|
13
15
|
it { is_expected.not_to be_defined_at(:boo) }
|
14
16
|
it { is_expected.not_to be_defined_at(2) }
|
15
17
|
end
|
16
18
|
|
17
|
-
context
|
19
|
+
context "double quotas" do
|
18
20
|
let(:pattern) { %(:"foo") }
|
19
21
|
|
20
22
|
it { is_expected.to be_defined_at(:foo) }
|
21
|
-
it { is_expected.not_to be_defined_at(
|
23
|
+
it { is_expected.not_to be_defined_at("foo") }
|
22
24
|
it { is_expected.not_to be_defined_at(:boo) }
|
23
25
|
it { is_expected.not_to be_defined_at(2) }
|
24
26
|
end
|
25
27
|
|
26
|
-
context
|
28
|
+
context "single quotas" do
|
27
29
|
let(:pattern) { %(:'foo') }
|
28
30
|
|
29
31
|
it { is_expected.to be_defined_at(:foo) }
|
30
|
-
it { is_expected.not_to be_defined_at(
|
32
|
+
it { is_expected.not_to be_defined_at("foo") }
|
31
33
|
it { is_expected.not_to be_defined_at(:boo) }
|
32
34
|
it { is_expected.not_to be_defined_at(2) }
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
|
-
describe
|
37
|
-
subject { matcher.
|
38
|
+
describe "#call" do
|
39
|
+
subject { matcher.(other) }
|
38
40
|
|
39
|
-
let(:pattern) {
|
41
|
+
let(:pattern) { ":foo" }
|
40
42
|
|
41
|
-
context
|
43
|
+
context "defined" do
|
42
44
|
let(:other) { :foo }
|
43
45
|
|
44
46
|
it { is_expected.to eq({}) }
|
45
47
|
end
|
46
48
|
end
|
47
49
|
|
48
|
-
describe
|
50
|
+
describe "#failure_reason" do
|
49
51
|
subject { matcher.failure_reason(other) }
|
50
52
|
|
51
|
-
context
|
53
|
+
context "match" do
|
52
54
|
let(:other) { :foo }
|
53
|
-
let(:pattern) {
|
55
|
+
let(:pattern) { ":foo" }
|
54
56
|
|
55
57
|
it { is_expected.to eq(Fear.none) }
|
56
58
|
end
|
57
59
|
|
58
|
-
context
|
60
|
+
context "does not match" do
|
59
61
|
let(:other) { :bar }
|
60
|
-
let(:pattern) {
|
62
|
+
let(:pattern) { ":foo" }
|
61
63
|
|
62
|
-
it { is_expected.to eq(Fear.some(
|
63
|
-
Expected `:bar` to match:
|
64
|
-
:foo
|
65
|
-
^
|
64
|
+
it { is_expected.to eq(Fear.some(<<~ERROR.strip)) }
|
65
|
+
Expected `:bar` to match:
|
66
|
+
:foo
|
67
|
+
^
|
66
68
|
ERROR
|
67
69
|
end
|
68
70
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe Fear::ExtractorApi do
|
2
4
|
def assert(value)
|
3
5
|
expect(value).to eq(true)
|
@@ -17,97 +19,97 @@ RSpec.describe Fear::ExtractorApi do
|
|
17
19
|
expect { yield }.not_to raise_error
|
18
20
|
end
|
19
21
|
|
20
|
-
specify
|
21
|
-
assert(Fear[
|
22
|
-
assert_not(Fear[
|
23
|
-
assert(Fear[
|
24
|
-
assert_not(Fear[
|
25
|
-
assert_not(Fear[
|
26
|
-
assert(Fear[
|
27
|
-
assert_not(Fear[
|
28
|
-
assert_not(Fear[
|
29
|
-
assert_not(Fear[
|
30
|
-
assert(Fear[
|
31
|
-
assert(Fear[
|
32
|
-
assert_not(Fear[
|
33
|
-
assert(Fear[
|
34
|
-
assert(Fear[
|
35
|
-
assert(Fear[
|
36
|
-
assert(Fear[
|
37
|
-
assert(Fear[
|
38
|
-
assert(Fear[
|
39
|
-
assert(Fear[
|
40
|
-
assert_invalid_syntax
|
41
|
-
assert_invalid_syntax
|
42
|
-
assert_invalid_syntax
|
43
|
-
assert_invalid_syntax
|
44
|
-
assert_invalid_syntax
|
45
|
-
assert_invalid_syntax
|
46
|
-
assert(Fear[
|
47
|
-
assert_not(Fear[
|
48
|
-
assert(Fear[
|
49
|
-
assert(Fear[
|
50
|
-
assert_not(Fear[
|
22
|
+
specify "Array" do
|
23
|
+
assert(Fear["[]"] === [])
|
24
|
+
assert_not(Fear["[]"] === [1])
|
25
|
+
assert(Fear["[1]"] === [1])
|
26
|
+
assert_not(Fear["[1]"] === [1, 2])
|
27
|
+
assert_not(Fear["[1]"] === [2])
|
28
|
+
assert(Fear["[1, 2]"] === [1, 2])
|
29
|
+
assert_not(Fear["[1, 2]"] === [1, 3])
|
30
|
+
assert_not(Fear["[1, 2]"] === [1, 2, 4])
|
31
|
+
assert_not(Fear["[1, 2]"] === [1])
|
32
|
+
assert(Fear["[*]"] === [])
|
33
|
+
assert(Fear["[*]"] === [1, 2])
|
34
|
+
assert_not(Fear["[1, *]"] === [])
|
35
|
+
assert(Fear["[1, *]"] === [1])
|
36
|
+
assert(Fear["[1, *]"] === [1, 2])
|
37
|
+
assert(Fear["[1, *]"] === [1, 2, 3])
|
38
|
+
assert(Fear["[[1]]"] === [[1]])
|
39
|
+
assert(Fear["[[1],2]"] === [[1], 2])
|
40
|
+
assert(Fear["[[1],*]"] === [[1], 2])
|
41
|
+
assert(Fear["[[*],*]"] === [[1], 2])
|
42
|
+
assert_invalid_syntax { Fear["[*, 2]"] }
|
43
|
+
assert_invalid_syntax { Fear["[*, ]"] }
|
44
|
+
assert_invalid_syntax { Fear["[1, *, ]"] }
|
45
|
+
assert_invalid_syntax { Fear["[1, *, 2]"] }
|
46
|
+
assert_invalid_syntax { Fear["[1, *, *]"] }
|
47
|
+
assert_invalid_syntax { Fear["[*, *]"] }
|
48
|
+
assert(Fear["[a, b]"] === [1, 2])
|
49
|
+
assert_not(Fear["[a, b, c]"] === [1, 2])
|
50
|
+
assert(Fear["[a, b, _]"] === [1, 2, 3])
|
51
|
+
assert(Fear["[a, b, *c]"] === [1, 2])
|
52
|
+
assert_not(Fear["[a, b, c, *d]"] === [1, 2])
|
51
53
|
end
|
52
54
|
|
53
|
-
specify
|
54
|
-
assert(Fear['"foo"'] ===
|
55
|
+
specify "String" do
|
56
|
+
assert(Fear['"foo"'] === "foo")
|
55
57
|
assert(Fear['"f\"oo"'] === 'f"oo')
|
56
|
-
assert_not(Fear['"foo"'] ===
|
57
|
-
assert(Fear["'foo'"] ===
|
58
|
-
assert_not(Fear["'foo'"] ===
|
58
|
+
assert_not(Fear['"foo"'] === "bar")
|
59
|
+
assert(Fear["'foo'"] === "foo")
|
60
|
+
assert_not(Fear["'foo'"] === "bar")
|
59
61
|
end
|
60
62
|
|
61
|
-
specify
|
63
|
+
specify "Symbol" do
|
62
64
|
assert(Fear[':"foo"'] === :foo)
|
63
65
|
assert(Fear[":'foo'"] === :foo)
|
64
|
-
assert(Fear[
|
65
|
-
assert_not(Fear[
|
66
|
+
assert(Fear[":foo"] === :foo)
|
67
|
+
assert_not(Fear[":foo"] === :bar)
|
66
68
|
end
|
67
69
|
|
68
|
-
specify
|
69
|
-
assert(Fear[
|
70
|
-
assert(Fear[
|
71
|
-
assert_not(Fear[
|
72
|
-
assert_not(Fear[
|
70
|
+
specify "Boolean" do
|
71
|
+
assert(Fear["true"] === true)
|
72
|
+
assert(Fear["false"] === false)
|
73
|
+
assert_not(Fear["true"] === false)
|
74
|
+
assert_not(Fear["false"] === true)
|
73
75
|
end
|
74
76
|
|
75
|
-
specify
|
76
|
-
assert(Fear[
|
77
|
-
assert_not(Fear[
|
77
|
+
specify "Nil" do
|
78
|
+
assert(Fear["nil"] === nil) # rubocop:disable Style/NilComparison
|
79
|
+
assert_not(Fear["nil"] === 42)
|
78
80
|
end
|
79
81
|
|
80
|
-
specify
|
81
|
-
assert(Fear[
|
82
|
-
assert(Fear[
|
83
|
-
assert(Fear[
|
84
|
-
assert(Fear[
|
85
|
-
assert(Fear[
|
86
|
-
assert(Fear[
|
82
|
+
specify "_" do
|
83
|
+
assert(Fear["_"] === nil) # rubocop:disable Style/NilComparison
|
84
|
+
assert(Fear["_"] === true)
|
85
|
+
assert(Fear["_"] === false)
|
86
|
+
assert(Fear["_"] === 42)
|
87
|
+
assert(Fear["_"] === "foo")
|
88
|
+
assert(Fear["_"] === [42])
|
87
89
|
end
|
88
90
|
|
89
|
-
specify
|
91
|
+
specify "type matching" do
|
90
92
|
class Foo
|
91
93
|
class Bar
|
92
94
|
end
|
93
95
|
end
|
94
96
|
|
95
|
-
assert(Fear[
|
96
|
-
assert_not(Fear[
|
97
|
-
assert(Fear[
|
98
|
-
assert(Fear[
|
99
|
-
assert(Fear[
|
100
|
-
assert_not(Fear[
|
97
|
+
assert(Fear["Integer"] === 3)
|
98
|
+
assert_not(Fear["Integer"] === "3")
|
99
|
+
assert(Fear["Numeric"] === 3)
|
100
|
+
assert(Fear["Foo::Bar"] === Foo::Bar.new)
|
101
|
+
assert(Fear["var : Integer"] === 3)
|
102
|
+
assert_not(Fear["var : Integer"] === "3")
|
101
103
|
end
|
102
104
|
|
103
|
-
specify
|
104
|
-
assert(Fear[
|
105
|
-
assert_not(Fear[
|
105
|
+
specify "capture matcher" do
|
106
|
+
assert(Fear["array @ [head : Integer, *tail]"] === [1, 2])
|
107
|
+
assert_not(Fear["array @ [head : Integer, *tail]"] === ["1", 2])
|
106
108
|
end
|
107
109
|
|
108
|
-
specify
|
109
|
-
assert_valid_syntax { Fear[
|
110
|
-
assert(Fear[
|
111
|
-
assert_not(Fear[
|
110
|
+
specify "extractor" do
|
111
|
+
assert_valid_syntax { Fear["Foo(a, b : Integer)"] }
|
112
|
+
assert(Fear["Fear::Some(a : Integer)"] === Fear.some(42))
|
113
|
+
assert_not(Fear["Fear::Some(a : Integer)"] === Fear.some("foo"))
|
112
114
|
end
|
113
115
|
end
|