opal 1.2.0.beta1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+ require 'test/unit'
2
+ require 'promise/v2'
3
+
4
+ class TestPromiseError < Test::Unit::TestCase
5
+ def test_rejects_the_promise_with_the_given_error
6
+ assert_equal(PromiseV2.error(23).error, 23)
7
+ end
8
+
9
+ def test_marks_the_promise_as_realized
10
+ assert_equal(PromiseV2.error(23).realized?, true)
11
+ end
12
+
13
+ def test_marks_the_promise_as_rejected
14
+ assert_equal(PromiseV2.error(23).rejected?, true)
15
+ end
16
+ end
@@ -0,0 +1,59 @@
1
+ require 'test/unit'
2
+ require 'promise/v2'
3
+
4
+ class TestPromiseRescue < Test::Unit::TestCase
5
+ def test_calls_the_block_when_the_promise_has_already_been_rejected
6
+ x = 42
7
+ PromiseV2.error(23)
8
+ .rescue { |v| x = v }
9
+ .always { assert_equal(x, 23) }
10
+ end
11
+
12
+ def test_calls_the_block_when_the_promise_is_rejected
13
+ a = PromiseV2.new
14
+ x = 42
15
+
16
+ pr = a.rescue { |v| x = v }
17
+ a.reject(23)
18
+
19
+ pr.always { assert_equal(x, 23) }
20
+ end
21
+
22
+ def test_does_not_call_then_blocks_when_the_promise_is_rejected
23
+ x = 42
24
+ y = 23
25
+
26
+ PromiseV2.error(23).then { y = 42 }.rescue { |v| x = v }.always do
27
+ assert_equal(x, 23)
28
+ assert_equal(y, 23)
29
+ end
30
+ end
31
+
32
+ def test_does_not_call_subsequent_rescue_blocks
33
+ x = 42
34
+ PromiseV2.error(23).rescue { |v| x = v }.rescue { x = 42 }.always do
35
+ assert_equal(x, 23)
36
+ end
37
+ end
38
+
39
+ def test_can_be_called_multiple_times_on_the_same_promise
40
+ p = PromiseV2.error(2)
41
+ x = 1
42
+
43
+ ps = []
44
+
45
+ ps << p.then { x += 1 }.rescue{}
46
+ ps << p.rescue { x += 3 }
47
+ ps << p.rescue { x += 3 }
48
+
49
+ PromiseV2.when(ps).always { assert_equal(x, 7) }
50
+ end
51
+
52
+ def test_raises_with_rescueB_if_a_promise_has_already_been_chained
53
+ p = PromiseV2.new
54
+
55
+ p.then! {}
56
+
57
+ assert_raise(ArgumentError) { p.rescue! {} }
58
+ end
59
+ end
@@ -0,0 +1,90 @@
1
+ require 'test/unit'
2
+ require 'promise/v2'
3
+
4
+ class TestPromiseThen < Test::Unit::TestCase
5
+ def test_calls_the_block_when_the_promise_has_already_been_resolved
6
+ x = 42
7
+ PromiseV2.value(23)
8
+ .then { |v| x = v }
9
+ .always { assert_equal(x, 23) }
10
+ end
11
+
12
+ def test_calls_the_block_when_the_promise_is_resolved
13
+ a = PromiseV2.new
14
+ x = 42
15
+
16
+ p = a.then { |v| x = v }
17
+ a.resolve(23)
18
+
19
+ p.always { assert_equal(x, 23) }
20
+ end
21
+
22
+ def test_works_with_multiple_chains
23
+ x = 42
24
+ PromiseV2.value(2)
25
+ .then { |v| v * 2 }
26
+ .then { |v| v * 4 }
27
+ .then { |v| x = v }
28
+ .always { assert_equal(x, 16) }
29
+ end
30
+
31
+ def test_works_when_a_block_returns_a_promise
32
+ a = PromiseV2.new
33
+ b = PromiseV2.new
34
+
35
+ x = 42
36
+ p = a.then { b }.then { |v| x = v }
37
+
38
+ a.resolve(42)
39
+ b.resolve(23)
40
+
41
+ p.always { assert_equal(x, 23) }
42
+ end
43
+
44
+ def test_sends_raised_exceptions_as_rejections
45
+ x = nil
46
+
47
+ PromiseV2.value(2)
48
+ .then { raise "hue" }
49
+ .rescue { |v| x = v }
50
+ .always { assert_equal(x.class, RuntimeError) }
51
+ end
52
+
53
+ def test_sends_raised_exceptions_inside_rescue_blocks_as_next_errors
54
+ x = nil
55
+
56
+ PromiseV2.value(2)
57
+ .then { raise "hue" }
58
+ .rescue { raise "omg" }
59
+ .rescue { |v| x = v }
60
+ .always { assert_equal(x.class, RuntimeError) }
61
+ end
62
+
63
+ def test_allows_then_to_be_called_multiple_times
64
+ pr = PromiseV2.value(2)
65
+ x = 1
66
+
67
+ ps = []
68
+
69
+ ps << pr.then { x += 1 }
70
+ ps << pr.then { x += 1 }
71
+
72
+ PromiseV2.when(ps).always { assert_equal(x, 3) }
73
+ end
74
+
75
+ def test_raises_with_thenB_if_a_promise_has_already_been_chained
76
+ pr = PromiseV2.new
77
+
78
+ pr.then! {}
79
+
80
+ assert_raise(ArgumentError) { pr.then! {} }
81
+ end
82
+
83
+ def test_should_pass_a_delayed_falsy_value
84
+ pr = PromiseV2.new.resolve(5).then { nil }
85
+
86
+ pr.always do |value|
87
+ assert_equal(value, nil)
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,52 @@
1
+ require 'test/unit'
2
+ require 'promise/v2'
3
+
4
+ class TestPromiseTrace < Test::Unit::TestCase
5
+ def test_calls_the_block_with_all_the_previous_results
6
+ x = 42
7
+
8
+ PromiseV2.value(1)
9
+ .then { 2 }
10
+ .then { 3 }
11
+ .trace {|a, b, c| x = a + b + c }
12
+ .always { assert_equal(x, 6) }
13
+ end
14
+
15
+ def test_calls_the_then_after_the_trace
16
+ x = 42
17
+
18
+ PromiseV2.value(1)
19
+ .then { 2 }
20
+ .then { 3 }
21
+ .trace { |a, b, c| a + b + c }
22
+ .then { |v| x = v }
23
+ .always { assert_equal(x, 6) }
24
+ end
25
+
26
+ def test_includes_the_first_value
27
+ x = 42
28
+
29
+ PromiseV2.value(1)
30
+ .trace { |a| x = a }
31
+ .always { assert_equal(x, 1) }
32
+ end
33
+
34
+ def test_works_after_a_when
35
+ x = 42
36
+
37
+ PromiseV2.value(1).then {
38
+ PromiseV2.when PromiseV2.value(2), PromiseV2.value(3)
39
+ }.trace {|a, b|
40
+ #x = a + b[0] + b[1]
41
+ x = "#{a},#{b}"
42
+ }.always { assert_equal(x, "1,native") } # 6
43
+ end
44
+
45
+ def test_raises_with_traceB_if_a_promise_has_already_been_chained
46
+ p = PromiseV2.new
47
+
48
+ p.then! {}
49
+
50
+ assert_raise(ArgumentError) { p.trace! {} }
51
+ end
52
+ end
@@ -0,0 +1,16 @@
1
+ require 'test/unit'
2
+ require 'promise/v2'
3
+
4
+ class TestPromiseValue < Test::Unit::TestCase
5
+ def test_resolves_the_promise_with_the_given_value
6
+ assert_equal(PromiseV2.value(23).value, 23)
7
+ end
8
+
9
+ def test_marks_the_promise_as_realized
10
+ assert_equal(PromiseV2.value(23).realized?, true)
11
+ end
12
+
13
+ def test_marks_the_promise_as_resolved
14
+ assert_equal(PromiseV2.value(23).resolved?, true)
15
+ end
16
+ end
@@ -0,0 +1,35 @@
1
+ require 'test/unit'
2
+ require 'promise/v2'
3
+
4
+ class TestPromiseWhen < Test::Unit::TestCase
5
+ def test_calls_the_block_with_all_promises_results
6
+ a = PromiseV2.new
7
+ b = PromiseV2.new
8
+
9
+ x = 42
10
+
11
+ p = PromiseV2.when(a, b).then {|y, z|
12
+ x = y + z
13
+ }
14
+
15
+ a.resolve(1)
16
+ b.resolve(2)
17
+
18
+ p.always { assert_equal(x, 3) }
19
+ end
20
+
21
+ def test_can_be_built_lazily
22
+ a = PromiseV2.new
23
+ b = PromiseV2.value(3)
24
+
25
+ x = 42
26
+
27
+ p = PromiseV2.when(a).and(b).then {|c, d|
28
+ x = c + d
29
+ }
30
+
31
+ a.resolve(2)
32
+
33
+ p.always { assert_equal(x, 5) }
34
+ end
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0.beta1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elia Schito
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2021-07-23 00:00:00.000000000 Z
13
+ date: 2021-07-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ast
@@ -562,6 +562,7 @@ files:
562
562
  - lib/opal/rewriters/mlhs_args.rb
563
563
  - lib/opal/rewriters/numblocks.rb
564
564
  - lib/opal/rewriters/opal_engine_check.rb
565
+ - lib/opal/rewriters/pattern_matching.rb
565
566
  - lib/opal/rewriters/returnable_logic.rb
566
567
  - lib/opal/rewriters/rubyspec/filters_rewriter.rb
567
568
  - lib/opal/server.rb
@@ -606,6 +607,7 @@ files:
606
607
  - opal/corelib/numeric.rb
607
608
  - opal/corelib/object_space.rb
608
609
  - opal/corelib/pack_unpack/format_string_parser.rb
610
+ - opal/corelib/pattern_matching.rb
609
611
  - opal/corelib/proc.rb
610
612
  - opal/corelib/process.rb
611
613
  - opal/corelib/random.rb
@@ -814,6 +816,7 @@ files:
814
816
  - spec/opal/core/language/keyword_arguments_spec.rb
815
817
  - spec/opal/core/language/memoization_spec.rb
816
818
  - spec/opal/core/language/numblocks_spec.rb
819
+ - spec/opal/core/language/pattern_matching_spec.rb
817
820
  - spec/opal/core/language/safe_navigator_spec.rb
818
821
  - spec/opal/core/language/while_spec.rb
819
822
  - spec/opal/core/language_spec.rb
@@ -1011,6 +1014,8 @@ files:
1011
1014
  - stdlib/pp.rb
1012
1015
  - stdlib/prettyprint.rb
1013
1016
  - stdlib/promise.rb
1017
+ - stdlib/promise/v1.rb
1018
+ - stdlib/promise/v2.rb
1014
1019
  - stdlib/racc/parser.rb
1015
1020
  - stdlib/rbconfig.rb
1016
1021
  - stdlib/rbconfig/sizeof.rb
@@ -1047,6 +1052,13 @@ files:
1047
1052
  - test/nodejs/test_string.rb
1048
1053
  - test/opal/cat.png
1049
1054
  - test/opal/http_server.rb
1055
+ - test/opal/promisev2/test_always.rb
1056
+ - test/opal/promisev2/test_error.rb
1057
+ - test/opal/promisev2/test_rescue.rb
1058
+ - test/opal/promisev2/test_then.rb
1059
+ - test/opal/promisev2/test_trace.rb
1060
+ - test/opal/promisev2/test_value.rb
1061
+ - test/opal/promisev2/test_when.rb
1050
1062
  - test/opal/test_base64.rb
1051
1063
  - test/opal/test_keyword.rb
1052
1064
  - test/opal/test_matrix.rb
@@ -1073,10 +1085,10 @@ licenses:
1073
1085
  metadata:
1074
1086
  homepage_uri: https://opalrb.com/
1075
1087
  bug_tracker_uri: https://github.com/opal/opal/issues
1076
- changelog_uri: https://github.com/opal/opal/blob/v1.2.0.beta1/CHANGELOG.md
1077
- readme_uri: https://github.com/opal/opal/blob/v1.2.0.beta1/README.md
1078
- api_documentation_uri: http://opalrb.com/docs/api/v1.2.0.beta1/index.html
1079
- guides_uri: http://opalrb.com/docs/guides/v1.2.0.beta1/index.html
1088
+ changelog_uri: https://github.com/opal/opal/blob/v1.2.0/CHANGELOG.md
1089
+ readme_uri: https://github.com/opal/opal/blob/v1.2.0/README.md
1090
+ api_documentation_uri: http://opalrb.com/docs/api/v1.2.0/index.html
1091
+ guides_uri: http://opalrb.com/docs/guides/v1.2.0/index.html
1080
1092
  chat_uri: https://gitter.im/opal/opal
1081
1093
  source_code_uri: https://github.com/opal/opal
1082
1094
  post_install_message:
@@ -1090,9 +1102,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
1090
1102
  version: '2.3'
1091
1103
  required_rubygems_version: !ruby/object:Gem::Requirement
1092
1104
  requirements:
1093
- - - ">"
1105
+ - - ">="
1094
1106
  - !ruby/object:Gem::Version
1095
- version: 1.3.1
1107
+ version: '0'
1096
1108
  requirements: []
1097
1109
  rubygems_version: 3.2.3
1098
1110
  signing_key:
@@ -1426,6 +1438,7 @@ test_files:
1426
1438
  - lib/opal/rewriters/mlhs_args.rb
1427
1439
  - lib/opal/rewriters/numblocks.rb
1428
1440
  - lib/opal/rewriters/opal_engine_check.rb
1441
+ - lib/opal/rewriters/pattern_matching.rb
1429
1442
  - lib/opal/rewriters/returnable_logic.rb
1430
1443
  - lib/opal/rewriters/rubyspec/filters_rewriter.rb
1431
1444
  - lib/opal/server.rb
@@ -1470,6 +1483,7 @@ test_files:
1470
1483
  - opal/corelib/numeric.rb
1471
1484
  - opal/corelib/object_space.rb
1472
1485
  - opal/corelib/pack_unpack/format_string_parser.rb
1486
+ - opal/corelib/pattern_matching.rb
1473
1487
  - opal/corelib/proc.rb
1474
1488
  - opal/corelib/process.rb
1475
1489
  - opal/corelib/random.rb
@@ -1613,6 +1627,8 @@ test_files:
1613
1627
  - stdlib/pp.rb
1614
1628
  - stdlib/prettyprint.rb
1615
1629
  - stdlib/promise.rb
1630
+ - stdlib/promise/v1.rb
1631
+ - stdlib/promise/v2.rb
1616
1632
  - stdlib/racc/parser.rb
1617
1633
  - stdlib/rbconfig.rb
1618
1634
  - stdlib/rbconfig/sizeof.rb