sashite-ggn 0.0.1 → 0.1.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.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +523 -521
  3. data/VERSION.semver +1 -1
  4. data/lib/sashite/ggn.rb +3 -2
  5. data/lib/sashite/ggn/ability.rb +11 -19
  6. data/lib/sashite/ggn/actor.rb +5 -13
  7. data/lib/sashite/ggn/ally.rb +6 -14
  8. data/lib/sashite/ggn/area.rb +6 -14
  9. data/lib/sashite/ggn/attacked.rb +6 -14
  10. data/lib/sashite/ggn/boolean.rb +6 -14
  11. data/lib/sashite/ggn/digit.rb +6 -14
  12. data/lib/sashite/ggn/digit_excluding_zero.rb +6 -14
  13. data/lib/sashite/ggn/direction.rb +6 -14
  14. data/lib/sashite/ggn/gameplay.rb +8 -28
  15. data/lib/sashite/ggn/gameplay_into_base64.rb +7 -14
  16. data/lib/sashite/ggn/integer.rb +6 -14
  17. data/lib/sashite/ggn/last_moved_actor.rb +6 -14
  18. data/lib/sashite/ggn/maximum_magnitude.rb +6 -14
  19. data/lib/sashite/ggn/name.rb +6 -14
  20. data/lib/sashite/ggn/negative_integer.rb +6 -14
  21. data/lib/sashite/ggn/null.rb +7 -9
  22. data/lib/sashite/ggn/object.rb +11 -19
  23. data/lib/sashite/ggn/occupied.rb +12 -20
  24. data/lib/sashite/ggn/pattern.rb +7 -16
  25. data/lib/sashite/ggn/previous_moves_counter.rb +6 -14
  26. data/lib/sashite/ggn/promotable_into_actors.rb +8 -17
  27. data/lib/sashite/ggn/required.rb +6 -14
  28. data/lib/sashite/ggn/self.rb +7 -9
  29. data/lib/sashite/ggn/square.rb +11 -19
  30. data/lib/sashite/ggn/state.rb +9 -17
  31. data/lib/sashite/ggn/subject.rb +11 -19
  32. data/lib/sashite/ggn/unsigned_integer.rb +6 -14
  33. data/lib/sashite/ggn/unsigned_integer_excluding_zero.rb +5 -13
  34. data/lib/sashite/ggn/verb.rb +15 -24
  35. data/lib/sashite/ggn/zero.rb +7 -9
  36. data/sashite-ggn.gemspec +2 -4
  37. data/test/test_ggn.rb +501 -495
  38. data/test/test_ggn_ability.rb +10 -10
  39. data/test/test_ggn_actor.rb +516 -536
  40. data/test/test_ggn_ally.rb +13 -29
  41. data/test/test_ggn_area.rb +9 -67
  42. data/test/test_ggn_attacked.rb +13 -29
  43. data/test/test_ggn_boolean.rb +10 -26
  44. data/test/test_ggn_digit.rb +10 -10
  45. data/test/test_ggn_digit_excluding_zero.rb +10 -11
  46. data/test/test_ggn_direction.rb +10 -10
  47. data/test/test_ggn_gameplay.rb +22 -38
  48. data/test/test_ggn_gameplay_into_base64.rb +511 -501
  49. data/test/test_ggn_integer.rb +19 -21
  50. data/test/test_ggn_last_moved_actor.rb +13 -29
  51. data/test/test_ggn_maximum_magnitude.rb +18 -16
  52. data/test/test_ggn_name.rb +9 -39
  53. data/test/test_ggn_negative_integer.rb +10 -10
  54. data/test/test_ggn_null.rb +10 -10
  55. data/test/test_ggn_object.rb +22 -24
  56. data/test/test_ggn_occupied.rb +40 -64
  57. data/test/test_ggn_pattern.rb +12 -10
  58. data/test/test_ggn_previous_moves_counter.rb +18 -20
  59. data/test/test_ggn_promotable_into_actors.rb +529 -549
  60. data/test/test_ggn_required.rb +10 -26
  61. data/test/test_ggn_self.rb +10 -10
  62. data/test/test_ggn_square.rb +14 -16
  63. data/test/test_ggn_state.rb +15 -19
  64. data/test/test_ggn_subject.rb +17 -19
  65. data/test/test_ggn_unsigned_integer.rb +30 -12
  66. data/test/test_ggn_unsigned_integer_excluding_zero.rb +14 -10
  67. data/test/test_ggn_verb.rb +16 -15
  68. data/test/test_ggn_zero.rb +10 -10
  69. metadata +4 -18
@@ -1,40 +1,38 @@
1
1
  require_relative '_test_helper'
2
2
 
3
3
  describe Sashite::GGN::Integer do
4
- describe '.new' do
5
- describe 'negative' do
6
- before do
7
- @integer = Sashite::GGN::Integer.new('-42')
8
- end
4
+ subject { Sashite::GGN::Integer }
9
5
 
10
- it 'returns the GGN as a JSON' do
11
- @integer.as_json.must_equal -42
6
+ describe '.load' do
7
+ describe 'negative integer' do
8
+ before do
9
+ @ggn_obj = '-42'
12
10
  end
13
11
 
14
- it 'returns the GGN as a string' do
15
- @integer.to_s.must_equal '-42'
12
+ it 'loads a document from the current io stream' do
13
+ subject.load(@ggn_obj).must_equal -42
16
14
  end
17
15
 
18
- it 'raises an error' do
19
- -> { Sashite::GGN::Integer.new('-01') }.must_raise ArgumentError
16
+ describe 'errors' do
17
+ it 'raises with the opposite of zero' do
18
+ -> { subject.load '-0' }.must_raise ArgumentError
19
+ end
20
20
  end
21
21
  end
22
22
 
23
- describe 'unsigned' do
23
+ describe 'unsigned integer' do
24
24
  before do
25
- @integer = Sashite::GGN::Integer.new('42')
26
- end
27
-
28
- it 'returns the GGN as a JSON' do
29
- @integer.as_json.must_equal 42
25
+ @ggn_obj = '42'
30
26
  end
31
27
 
32
- it 'returns the GGN as a string' do
33
- @integer.to_s.must_equal '42'
28
+ it 'loads a document from the current io stream' do
29
+ subject.load(@ggn_obj).must_equal 42
34
30
  end
35
31
 
36
- it 'raises an error' do
37
- -> { Sashite::GGN::Integer.new('01') }.must_raise ArgumentError
32
+ describe 'errors' do
33
+ it 'raises with an integer beginning by zero' do
34
+ -> { subject.load '04' }.must_raise ArgumentError
35
+ end
38
36
  end
39
37
  end
40
38
  end
@@ -1,51 +1,35 @@
1
1
  require_relative '_test_helper'
2
2
 
3
3
  describe Sashite::GGN::LastMovedActor do
4
- describe '.new' do
5
- describe 'false' do
6
- before do
7
- @last_moved_actor = Sashite::GGN::LastMovedActor.new('f')
8
- end
4
+ subject { Sashite::GGN::LastMovedActor }
9
5
 
10
- it 'returns the GGN as a JSON' do
11
- @last_moved_actor.as_json.must_equal false
12
- end
13
-
14
- it 'returns the GGN as a string' do
15
- @last_moved_actor.to_s.must_equal 'f'
16
- end
17
- end
18
-
19
- describe 'true' do
6
+ describe '.load' do
7
+ describe 'boolean' do
20
8
  before do
21
- @last_moved_actor = Sashite::GGN::LastMovedActor.new('t')
9
+ @ggn_obj = 't'
22
10
  end
23
11
 
24
- it 'returns the GGN as a JSON' do
25
- @last_moved_actor.as_json.must_equal true
12
+ it 'loads a document from the current io stream' do
13
+ subject.load(@ggn_obj).must_equal true
26
14
  end
27
15
 
28
- it 'returns the GGN as a string' do
29
- @last_moved_actor.to_s.must_equal 't'
16
+ it 'raises an error' do
17
+ -> { subject.load 'true' }.must_raise ArgumentError
30
18
  end
31
19
  end
32
20
 
33
21
  describe 'null' do
34
22
  before do
35
- @last_moved_actor = Sashite::GGN::LastMovedActor.new('_')
23
+ @ggn_obj = '_'
36
24
  end
37
25
 
38
- it 'returns the GGN as a JSON' do
39
- @last_moved_actor.as_json.must_equal nil
26
+ it 'loads a document from the current io stream' do
27
+ subject.load(@ggn_obj).must_equal nil
40
28
  end
41
29
 
42
- it 'returns the GGN as a string' do
43
- @last_moved_actor.to_s.must_equal '_'
30
+ it 'raises an error' do
31
+ -> { subject.load '' }.must_raise ArgumentError
44
32
  end
45
33
  end
46
34
  end
47
-
48
- it 'raises an error' do
49
- -> { Sashite::GGN::LastMovedActor.new('foobar') }.must_raise ArgumentError
50
- end
51
35
  end
@@ -1,37 +1,39 @@
1
1
  require_relative '_test_helper'
2
2
 
3
3
  describe Sashite::GGN::MaximumMagnitude do
4
- describe '.new' do
4
+ subject { Sashite::GGN::MaximumMagnitude }
5
+
6
+ describe '.load' do
5
7
  describe 'null' do
6
8
  before do
7
- @maximum_magnitude = Sashite::GGN::MaximumMagnitude.new('_')
9
+ @ggn_obj = '_'
8
10
  end
9
11
 
10
- it 'returns the GGN as a JSON' do
11
- @maximum_magnitude.as_json.must_equal nil
12
+ it 'loads a document from the current io stream' do
13
+ subject.load(@ggn_obj).must_equal nil
12
14
  end
13
15
 
14
- it 'returns the GGN as a string' do
15
- @maximum_magnitude.to_s.must_equal '_'
16
+ describe 'errors' do
17
+ it 'raises an error' do
18
+ -> { subject.load 'foobar' }.must_raise ArgumentError
19
+ end
16
20
  end
17
21
  end
18
22
 
19
- describe 'unsigned integer' do
23
+ describe 'an unsigned integer' do
20
24
  before do
21
- @maximum_magnitude = Sashite::GGN::MaximumMagnitude.new('42')
25
+ @ggn_obj = '42'
22
26
  end
23
27
 
24
- it 'returns the GGN as a JSON' do
25
- @maximum_magnitude.as_json.must_equal 42
28
+ it 'loads a document from the current io stream' do
29
+ subject.load(@ggn_obj).must_equal 42
26
30
  end
27
31
 
28
- it 'returns the GGN as a string' do
29
- @maximum_magnitude.to_s.must_equal '42'
32
+ describe 'errors' do
33
+ it 'raises an error' do
34
+ -> { subject.load '-4' }.must_raise ArgumentError
35
+ end
30
36
  end
31
37
  end
32
38
  end
33
-
34
- it 'raises an error' do
35
- -> { Sashite::GGN::MaximumMagnitude.new('0') }.must_raise ArgumentError
36
- end
37
39
  end
@@ -1,51 +1,21 @@
1
1
  require_relative '_test_helper'
2
2
 
3
3
  describe Sashite::GGN::Name do
4
- describe '.new' do
5
- describe 'capture' do
6
- before do
7
- @name = Sashite::GGN::Name.new('capture')
8
- end
9
-
10
- it 'returns the GGN as a JSON' do
11
- @name.as_json.must_equal :capture
12
- end
4
+ subject { Sashite::GGN::Name }
13
5
 
14
- it 'returns the GGN as a string' do
15
- @name.to_s.must_equal 'capture'
16
- end
6
+ describe '.load' do
7
+ before do
8
+ @ggn_obj = 'capture'
17
9
  end
18
10
 
19
- describe 'remove' do
20
- before do
21
- @name = Sashite::GGN::Name.new('remove')
22
- end
23
-
24
- it 'returns the GGN as a JSON' do
25
- @name.as_json.must_equal :remove
26
- end
27
-
28
- it 'returns the GGN as a string' do
29
- @name.to_s.must_equal 'remove'
30
- end
11
+ it 'loads a document from the current io stream' do
12
+ subject.load(@ggn_obj).must_equal :capture
31
13
  end
32
14
 
33
- describe 'shift' do
34
- before do
35
- @name = Sashite::GGN::Name.new('shift')
36
- end
37
-
38
- it 'returns the GGN as a JSON' do
39
- @name.as_json.must_equal :shift
40
- end
41
-
42
- it 'returns the GGN as a string' do
43
- @name.to_s.must_equal 'shift'
15
+ describe 'errors' do
16
+ it 'raises an error' do
17
+ -> { subject.load 'foobar' }.must_raise ArgumentError
44
18
  end
45
19
  end
46
20
  end
47
-
48
- it 'raises an error' do
49
- -> { Sashite::GGN::Name.new('foobar') }.must_raise ArgumentError
50
- end
51
21
  end
@@ -1,21 +1,21 @@
1
1
  require_relative '_test_helper'
2
2
 
3
3
  describe Sashite::GGN::NegativeInteger do
4
- describe '.new' do
4
+ subject { Sashite::GGN::NegativeInteger }
5
+
6
+ describe '.load' do
5
7
  before do
6
- @negative_integer = Sashite::GGN::NegativeInteger.new('-42')
8
+ @ggn_obj = '-42'
7
9
  end
8
10
 
9
- it 'returns the GGN as a JSON' do
10
- @negative_integer.as_json.must_equal -42
11
+ it 'loads a document from the current io stream' do
12
+ subject.load(@ggn_obj).must_equal -42
11
13
  end
12
14
 
13
- it 'returns the GGN as a string' do
14
- @negative_integer.to_s.must_equal '-42'
15
+ describe 'errors' do
16
+ it 'raises with an unsigned integer' do
17
+ -> { subject.load '4' }.must_raise ArgumentError
18
+ end
15
19
  end
16
20
  end
17
-
18
- it 'raises an error' do
19
- -> { Sashite::GGN::NegativeInteger.new('42') }.must_raise ArgumentError
20
- end
21
21
  end
@@ -1,21 +1,21 @@
1
1
  require_relative '_test_helper'
2
2
 
3
3
  describe Sashite::GGN::Null do
4
- describe '.instance' do
4
+ subject { Sashite::GGN::Null }
5
+
6
+ describe '.load' do
5
7
  before do
6
- @null = Sashite::GGN::Null.instance
8
+ @ggn_obj = '_'
7
9
  end
8
10
 
9
- it 'returns the GGN as a JSON' do
10
- @null.as_json.must_be_nil
11
+ it 'loads a document from the current io stream' do
12
+ subject.load(@ggn_obj).must_equal nil
11
13
  end
12
14
 
13
- it 'returns the GGN as a string' do
14
- @null.to_s.must_equal '_'
15
+ describe 'errors' do
16
+ it 'raises without null' do
17
+ -> { subject.load '4' }.must_raise ArgumentError
18
+ end
15
19
  end
16
20
  end
17
-
18
- it 'is false' do
19
- Sashite::GGN::Null.valid?('foobar').must_equal false
20
- end
21
21
  end
@@ -1,35 +1,33 @@
1
1
  require_relative '_test_helper'
2
2
 
3
3
  describe Sashite::GGN::Object do
4
- describe '.new' do
4
+ subject { Sashite::GGN::Object }
5
+
6
+ describe '.load' do
5
7
  before do
6
- @object = Sashite::GGN::Object.new('_@f+all~_@f+all%self')
8
+ @ggn_obj = '_@f+all~_@f+all%self'
7
9
  end
8
10
 
9
- it 'returns the GGN as a JSON' do
10
- @object.as_json.hash.must_equal(
11
- {
12
- src_square: {
13
- :"...attacked?" => nil,
14
- :"...occupied!" => false,
15
- area: :all
16
- },
17
- dst_square: {
18
- :"...attacked?" => nil,
19
- :"...occupied!" => false,
20
- area: :all
21
- },
22
- promotable_into_actors: [:self]
23
- }.hash
24
- )
11
+ it 'loads a document from the current io stream' do
12
+ subject.load(@ggn_obj).hash.must_equal({
13
+ src_square: {
14
+ :"...attacked?" => nil,
15
+ :"...occupied!" => false,
16
+ area: :all
17
+ },
18
+ dst_square: {
19
+ :"...attacked?" => nil,
20
+ :"...occupied!" => false,
21
+ area: :all
22
+ },
23
+ promotable_into_actors: [:self]
24
+ }.hash)
25
25
  end
26
26
 
27
- it 'returns the GGN as a string' do
28
- @object.to_s.must_equal '_@f+all~_@f+all%self'
27
+ describe 'errors' do
28
+ it 'raises without an object' do
29
+ -> { subject.load 'foo' }.must_raise ArgumentError
30
+ end
29
31
  end
30
32
  end
31
-
32
- it 'raises an error' do
33
- -> { Sashite::GGN::Object.new('foo') }.must_raise ArgumentError
34
- end
35
33
  end
@@ -1,102 +1,78 @@
1
1
  require_relative '_test_helper'
2
2
 
3
3
  describe Sashite::GGN::Occupied do
4
- describe '.new' do
5
- describe 'an ally actor' do
6
- before do
7
- @occupied = Sashite::GGN::Occupied.new('an_ally_actor')
8
- end
9
-
10
- it 'returns the GGN as a JSON' do
11
- @occupied.as_json.must_equal :an_ally_actor
12
- end
13
-
14
- it 'returns the GGN as a string' do
15
- @occupied.to_s.must_equal 'an_ally_actor'
16
- end
17
- end
4
+ subject { Sashite::GGN::Occupied }
18
5
 
19
- describe 'an enemy actor' do
6
+ describe '.load' do
7
+ describe 'a relationship' do
20
8
  before do
21
- @occupied = Sashite::GGN::Occupied.new('an_enemy_actor')
9
+ @ggn_obj = 'an_ally_actor'
22
10
  end
23
11
 
24
- it 'returns the GGN as a JSON' do
25
- @occupied.as_json.must_equal :an_enemy_actor
12
+ it 'loads a document from the current io stream' do
13
+ subject.load(@ggn_obj).must_equal :an_ally_actor
26
14
  end
27
15
 
28
- it 'returns the GGN as a string' do
29
- @occupied.to_s.must_equal 'an_enemy_actor'
16
+ describe 'errors' do
17
+ it 'raises without a relationship' do
18
+ -> { subject.load 'foobar' }.must_raise ArgumentError
19
+ end
30
20
  end
31
21
  end
32
22
 
33
- describe 'null' do
23
+ describe 'a boolean' do
34
24
  before do
35
- @occupied = Sashite::GGN::Occupied.new('_')
25
+ @ggn_obj = 'f'
36
26
  end
37
27
 
38
- it 'returns the GGN as a JSON' do
39
- @occupied.as_json.must_equal nil
28
+ it 'loads a document from the current io stream' do
29
+ subject.load(@ggn_obj).must_equal false
40
30
  end
41
31
 
42
- it 'returns the GGN as a string' do
43
- @occupied.to_s.must_equal '_'
32
+ describe 'errors' do
33
+ it 'raises without a boolean' do
34
+ -> { subject.load 'foobar' }.must_raise ArgumentError
35
+ end
44
36
  end
45
37
  end
46
38
 
47
- describe 'true' do
48
- before do
49
- @occupied = Sashite::GGN::Occupied.new('t')
50
- end
51
-
52
- it 'returns the GGN as a JSON' do
53
- @occupied.as_json.must_equal true
54
- end
55
-
56
- it 'returns the GGN as a string' do
57
- @occupied.to_s.must_equal 't'
58
- end
59
- end
60
-
61
- describe 'false' do
39
+ describe 'null' do
62
40
  before do
63
- @occupied = Sashite::GGN::Occupied.new('f')
41
+ @ggn_obj = '_'
64
42
  end
65
43
 
66
- it 'returns the GGN as a JSON' do
67
- @occupied.as_json.must_equal false
44
+ it 'loads a document from the current io stream' do
45
+ subject.load(@ggn_obj).must_equal nil
68
46
  end
69
47
 
70
- it 'returns the GGN as a string' do
71
- @occupied.to_s.must_equal 'f'
48
+ describe 'errors' do
49
+ it 'raises without null' do
50
+ -> { subject.load '' }.must_raise ArgumentError
51
+ end
72
52
  end
73
53
  end
74
54
 
75
55
  describe 'a subject' do
76
56
  before do
77
- @occupied = Sashite::GGN::Occupied.new('f<self>_&_')
57
+ @ggn_obj = 'f<self>_&_'
78
58
  end
79
59
 
80
- it 'returns the GGN as a JSON' do
81
- @occupied.as_json.hash.must_equal(
82
- {
83
- :"...ally?" => false,
84
- actor: :self,
85
- state: {
86
- :"...last_moved_actor?" => nil,
87
- :"...previous_moves_counter" => nil
88
- }
89
- }.hash
90
- )
60
+ it 'loads a document from the current io stream' do
61
+ subject.load(@ggn_obj).hash.must_equal({
62
+ :"...ally?" => false,
63
+ actor: :self,
64
+ state: {
65
+ :"...last_moved_actor?" => nil,
66
+ :"...previous_moves_counter" => nil
67
+ }
68
+ }.hash)
91
69
  end
92
70
 
93
- it 'returns the GGN as a string' do
94
- @occupied.to_s.must_equal 'f<self>_&_'
71
+ describe 'errors' do
72
+ it 'raises without a well-formed subject' do
73
+ -> { subject.load 'f<foo>_&_' }.must_raise ArgumentError
74
+ end
95
75
  end
96
76
  end
97
77
  end
98
-
99
- it 'raises an error' do
100
- -> { Sashite::GGN::Occupied.new('foobar') }.must_raise ArgumentError
101
- end
102
78
  end