fortio-namelist 1.0.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,81 @@
1
+ require "fortio-namelist"
2
+ require "rspec-power_assert"
3
+
4
+ describe "FortIO::Namelist" do
5
+
6
+ example "only letter" do
7
+ input = %{
8
+ &example
9
+ a = 1
10
+ ab = 1
11
+ abc = 1
12
+ /
13
+ }
14
+ nml = FortIO::Namelist.parse(input)
15
+ is_asserted_by { nml.has_key? :example }
16
+ is_asserted_by { nml[:example].is_a? Hash }
17
+ is_asserted_by { nml[:example].keys.size == 3 }
18
+ is_asserted_by { nml[:example].keys == [:a,:ab,:abc] }
19
+ end
20
+
21
+ example "letter number" do
22
+ input = %{
23
+ &example
24
+ a1 = 1
25
+ ab12 = 1
26
+ abc123 = 1
27
+ /
28
+ }
29
+ nml = FortIO::Namelist.parse(input)
30
+ is_asserted_by { nml.has_key? :example }
31
+ is_asserted_by { nml[:example].is_a? Hash }
32
+ is_asserted_by { nml[:example].keys.size == 3 }
33
+ is_asserted_by { nml[:example].keys == [:a1, :ab12, :abc123] }
34
+ end
35
+
36
+ example "leter number underbar" do
37
+ input = %{
38
+ &example
39
+ a_1 = 1
40
+ ab_12 = 1
41
+ abc_123 = 1
42
+ /
43
+ }
44
+ nml = FortIO::Namelist.parse(input)
45
+ is_asserted_by { nml.has_key? :example }
46
+ is_asserted_by { nml[:example].is_a? Hash }
47
+ is_asserted_by { nml[:example].keys.size == 3 }
48
+ is_asserted_by { nml[:example].keys == [:a_1, :ab_12, :abc_123] }
49
+ end
50
+
51
+ example "can't start with number" do
52
+ input = %{
53
+ &example
54
+ 1a = 1
55
+ /
56
+ }
57
+ expect { FortIO::Namelist.parse(input) }.to raise_error(RuntimeError)
58
+ end
59
+
60
+ example "can't start with underscore" do
61
+ input = %{
62
+ &example
63
+ _a = 1
64
+ /
65
+ }
66
+ expect { FortIO::Namelist.parse(input) }.to raise_error(RuntimeError)
67
+ end
68
+
69
+ example "t and f can be used as indentifier" do
70
+ input = %{
71
+ &example
72
+ t = 1
73
+ f = 2
74
+ /
75
+ }
76
+ nml = FortIO::Namelist.parse(input)
77
+ is_asserted_by { nml[:example][:t] == 1 }
78
+ is_asserted_by { nml[:example][:f] == 2 }
79
+ end
80
+
81
+ end
@@ -0,0 +1,196 @@
1
+ require "fortio-namelist"
2
+ require "rspec-power_assert"
3
+
4
+ describe "FortIO::Namelist" do
5
+
6
+ example "integer" do
7
+ input = %{
8
+ &example
9
+ v1 = 1
10
+ v2 = -1
11
+ v3 = 01
12
+ v4 = -01
13
+ /
14
+ }
15
+ nml = FortIO::Namelist.parse(input)
16
+ is_asserted_by { nml.has_key? :example }
17
+ is_asserted_by { nml[:example].is_a? Hash }
18
+ is_asserted_by { nml[:example][:v1] == 1 }
19
+ is_asserted_by { nml[:example][:v2] == -1 }
20
+ is_asserted_by { nml[:example][:v3] == 1 }
21
+ is_asserted_by { nml[:example][:v4] == -1 }
22
+ end
23
+
24
+ example "float positive" do
25
+ input = %{
26
+ &example
27
+ v1 = 1.0
28
+ v2 = 2.
29
+ v3 = 3.0d0
30
+ v4 = 4.d0
31
+ v5 = 5d0
32
+ v6 = 6.0d+0
33
+ v7 = 7.0d+00
34
+ v8 = 80.0d-1
35
+ v9 = 90.0d-01
36
+ /
37
+ }
38
+ nml = FortIO::Namelist.parse(input)
39
+ is_asserted_by { nml.has_key? :example }
40
+ is_asserted_by { nml[:example].is_a? Hash }
41
+ is_asserted_by { nml[:example][:v1] == 1.0 }
42
+ is_asserted_by { nml[:example][:v2] == 2.0 }
43
+ is_asserted_by { nml[:example][:v3] == 3.0 }
44
+ is_asserted_by { nml[:example][:v4] == 4.0 }
45
+ is_asserted_by { nml[:example][:v5] == 5.0 }
46
+ is_asserted_by { nml[:example][:v6] == 6.0 }
47
+ is_asserted_by { nml[:example][:v7] == 7.0 }
48
+ is_asserted_by { nml[:example][:v8] == 8.0 }
49
+ is_asserted_by { nml[:example][:v9] == 9.0 }
50
+ end
51
+
52
+ example "float negative" do
53
+ input = %{
54
+ &example
55
+ v1 = -1.0
56
+ v2 = -2.
57
+ v3 = -3.0d0
58
+ v4 = -4.d0
59
+ v5 = -5d0
60
+ v6 = -6.0d+0
61
+ v7 = -7.0d+00
62
+ v8 = -80.0d-1
63
+ v9 = -90.0d-01
64
+ /
65
+ }
66
+ nml = FortIO::Namelist.parse(input)
67
+ is_asserted_by { nml.has_key? :example }
68
+ is_asserted_by { nml[:example].is_a? Hash }
69
+ is_asserted_by { nml[:example][:v1] == -1.0 }
70
+ is_asserted_by { nml[:example][:v2] == -2.0 }
71
+ is_asserted_by { nml[:example][:v3] == -3.0 }
72
+ is_asserted_by { nml[:example][:v4] == -4.0 }
73
+ is_asserted_by { nml[:example][:v5] == -5.0 }
74
+ is_asserted_by { nml[:example][:v6] == -6.0 }
75
+ is_asserted_by { nml[:example][:v7] == -7.0 }
76
+ is_asserted_by { nml[:example][:v8] == -8.0 }
77
+ is_asserted_by { nml[:example][:v9] == -9.0 }
78
+ end
79
+
80
+ example "float 0 start" do
81
+ input = %{
82
+ &example
83
+ v1 = 01.0
84
+ /
85
+ }
86
+ nml = FortIO::Namelist.parse(input)
87
+ is_asserted_by { nml.has_key? :example }
88
+ is_asserted_by { nml[:example].is_a? Hash }
89
+ is_asserted_by { nml[:example][:v1] == 1.0 }
90
+ end
91
+
92
+ example "string" do
93
+ input = %{
94
+ &example
95
+ v1 = 'string'
96
+ v2 = "string"
97
+ v3 = string
98
+ /
99
+ }
100
+ nml = FortIO::Namelist.parse(input)
101
+ is_asserted_by { nml.has_key? :example }
102
+ is_asserted_by { nml[:example].is_a? Hash }
103
+ is_asserted_by { nml[:example][:v1] == "string" }
104
+ is_asserted_by { nml[:example][:v2] == "string" }
105
+ is_asserted_by { nml[:example][:v3] == "string" }
106
+ end
107
+
108
+ example "without quotation mark" do
109
+ input = %{
110
+ &example
111
+ v1 = string
112
+ v2 = _string
113
+ v3 = 0_string
114
+ /
115
+ }
116
+ nml = FortIO::Namelist.parse(input)
117
+ is_asserted_by { nml.has_key? :example }
118
+ is_asserted_by { nml[:example].is_a? Hash }
119
+ is_asserted_by { nml[:example][:v1] == "string" }
120
+ is_asserted_by { nml[:example][:v2] == "_string" }
121
+ is_asserted_by { nml[:example][:v3] == "0_string" }
122
+ end
123
+
124
+ example "logical true" do
125
+ input = %{
126
+ &example
127
+ v1 = .true.
128
+ v2 = .TRUE.
129
+ v3 = .t
130
+ v4 = .t_0a2
131
+ v5 = t
132
+ v6 = T
133
+ /
134
+ }
135
+ nml = FortIO::Namelist.parse(input)
136
+ is_asserted_by { nml.has_key? :example }
137
+ is_asserted_by { nml[:example].is_a? Hash }
138
+ is_asserted_by { nml[:example][:v1] == true }
139
+ is_asserted_by { nml[:example][:v2] == true }
140
+ is_asserted_by { nml[:example][:v3] == true }
141
+ is_asserted_by { nml[:example][:v4] == true }
142
+ is_asserted_by { nml[:example][:v5] == true }
143
+ is_asserted_by { nml[:example][:v6] == true }
144
+ end
145
+
146
+ example "logical false" do
147
+ input = %{
148
+ &example
149
+ v1 = .false.
150
+ v2 = .FALSE.
151
+ v3 = .f
152
+ v4 = .f_0b2
153
+ v5 = f
154
+ v6 = F
155
+ /
156
+ }
157
+ nml = FortIO::Namelist.parse(input)
158
+ is_asserted_by { nml.has_key? :example }
159
+ is_asserted_by { nml[:example].is_a? Hash }
160
+ is_asserted_by { nml[:example][:v1] == false }
161
+ is_asserted_by { nml[:example][:v2] == false }
162
+ is_asserted_by { nml[:example][:v3] == false }
163
+ is_asserted_by { nml[:example][:v4] == false }
164
+ is_asserted_by { nml[:example][:v5] == false }
165
+ is_asserted_by { nml[:example][:v6] == false }
166
+ end
167
+
168
+ example "complex" do
169
+ input = %{
170
+ &example
171
+ v1 = (1,1)
172
+ v2 = (1d0,1d0)
173
+ /
174
+ }
175
+ nml = FortIO::Namelist.parse(input)
176
+ is_asserted_by { nml.has_key? :example }
177
+ is_asserted_by { nml[:example].is_a? Hash }
178
+ is_asserted_by { nml[:example][:v1] == 1+1i }
179
+ is_asserted_by { nml[:example][:v2] == 1+1i }
180
+ end
181
+
182
+ example "nil asign" do
183
+ input = %{
184
+ &example
185
+ v1 = ,
186
+ v2 = ,
187
+ /
188
+ }
189
+ nml = FortIO::Namelist.parse(input)
190
+ is_asserted_by { nml.has_key? :example }
191
+ is_asserted_by { nml[:example].is_a? Hash }
192
+ is_asserted_by { nml[:example][:v1] == "" }
193
+ is_asserted_by { nml[:example][:v2] == "" }
194
+ end
195
+
196
+ end
@@ -0,0 +1,162 @@
1
+ require "fortio-namelist"
2
+ require "rspec-power_assert"
3
+
4
+ describe "FortIO::Namelist" do
5
+
6
+ example "newline enumeration" do
7
+ input = %{
8
+ &example
9
+ a = 1
10
+ ab = 2
11
+ abc = 3
12
+ /
13
+ }
14
+ nml = FortIO::Namelist.parse(input)
15
+ is_asserted_by { nml.has_key? :example }
16
+ is_asserted_by { nml[:example].is_a? Hash }
17
+ is_asserted_by { nml[:example].keys.size == 3 }
18
+ is_asserted_by { nml[:example].keys == [:a,:ab,:abc] }
19
+ is_asserted_by { nml[:example].values == [1,2,3] }
20
+ end
21
+
22
+ example "space enumeration" do
23
+ input = %{
24
+ &example a = 1 ab = 2 abc = 3 /
25
+ }
26
+ nml = FortIO::Namelist.parse(input)
27
+ is_asserted_by { nml.has_key? :example }
28
+ is_asserted_by { nml[:example].is_a? Hash }
29
+ is_asserted_by { nml[:example].keys.size == 3 }
30
+ is_asserted_by { nml[:example].keys == [:a,:ab,:abc] }
31
+ is_asserted_by { nml[:example].values == [1,2,3] }
32
+ end
33
+
34
+ example "space enumeration 2" do
35
+ input = %{
36
+ &example
37
+ a = 1 ab = 2 abc = 3
38
+ /
39
+ }
40
+ nml = FortIO::Namelist.parse(input)
41
+ is_asserted_by { nml.has_key? :example }
42
+ is_asserted_by { nml[:example].is_a? Hash }
43
+ is_asserted_by { nml[:example].keys.size == 3 }
44
+ is_asserted_by { nml[:example].keys == [:a,:ab,:abc] }
45
+ is_asserted_by { nml[:example].values == [1,2,3] }
46
+ end
47
+
48
+ example "comma enumeration" do
49
+ input = %{
50
+ &example a = 1, ab = 2, abc = 3 /
51
+ }
52
+ nml = FortIO::Namelist.parse(input)
53
+ is_asserted_by { nml.has_key? :example }
54
+ is_asserted_by { nml[:example].is_a? Hash }
55
+ is_asserted_by { nml[:example].keys.size == 3 }
56
+ is_asserted_by { nml[:example].keys == [:a,:ab,:abc] }
57
+ is_asserted_by { nml[:example].values == [1,2,3] }
58
+ end
59
+
60
+ example "comma enumeration 2" do
61
+ input = %{
62
+ &example
63
+ a = 1, ab = 2, abc = 3
64
+ /
65
+ }
66
+ nml = FortIO::Namelist.parse(input)
67
+ is_asserted_by { nml.has_key? :example }
68
+ is_asserted_by { nml[:example].is_a? Hash }
69
+ is_asserted_by { nml[:example].keys.size == 3 }
70
+ is_asserted_by { nml[:example].keys == [:a,:ab,:abc] }
71
+ is_asserted_by { nml[:example].values == [1,2,3] }
72
+ end
73
+
74
+ example "comma newline enumeration" do
75
+ input = %{
76
+ &example
77
+ a = 1,
78
+ ab = 2,
79
+ abc = 3
80
+ /
81
+ }
82
+ nml = FortIO::Namelist.parse(input)
83
+ is_asserted_by { nml.has_key? :example }
84
+ is_asserted_by { nml[:example].is_a? Hash }
85
+ is_asserted_by { nml[:example].keys.size == 3 }
86
+ is_asserted_by { nml[:example].keys == [:a,:ab,:abc] }
87
+ is_asserted_by { nml[:example].values == [1,2,3] }
88
+ end
89
+
90
+ example "last comma is permitted" do
91
+ input = %{
92
+ &example
93
+ a = 1,
94
+ ab = 2,
95
+ abc = 3,
96
+ /
97
+ }
98
+ nml = FortIO::Namelist.parse(input)
99
+ is_asserted_by { nml.has_key? :example }
100
+ is_asserted_by { nml[:example].is_a? Hash }
101
+ is_asserted_by { nml[:example].keys.size == 3 }
102
+ is_asserted_by { nml[:example].keys == [:a,:ab,:abc] }
103
+ is_asserted_by { nml[:example].values == [1,2,3] }
104
+ end
105
+
106
+ example "comma space hybrid" do
107
+ input = %{
108
+ &example
109
+ a = 1 ab = 2,
110
+ abc = 3
111
+ /
112
+ }
113
+ nml = FortIO::Namelist.parse(input)
114
+ is_asserted_by { nml.has_key? :example }
115
+ is_asserted_by { nml[:example].is_a? Hash }
116
+ is_asserted_by { nml[:example].keys.size == 3 }
117
+ is_asserted_by { nml[:example].keys == [:a,:ab,:abc] }
118
+ is_asserted_by { nml[:example].values == [1,2,3] }
119
+ end
120
+
121
+ example "space before and after equal symbol" do
122
+ input = %{
123
+ &example
124
+ a = 1
125
+ ab= 2
126
+ abc =3
127
+ /
128
+ }
129
+ nml = FortIO::Namelist.parse(input)
130
+ is_asserted_by { nml.has_key? :example }
131
+ is_asserted_by { nml[:example].is_a? Hash }
132
+ is_asserted_by { nml[:example].keys.size == 3 }
133
+ is_asserted_by { nml[:example].keys == [:a,:ab,:abc] }
134
+ is_asserted_by { nml[:example].values == [1,2,3] }
135
+ end
136
+
137
+ example "newline before and after equal symbol" do
138
+ input = %{
139
+ &example
140
+ a =
141
+ 1
142
+ b
143
+ = 2
144
+ c
145
+ =
146
+ 3
147
+ ,
148
+ d
149
+ =
150
+ 4
151
+ /
152
+ }
153
+ nml = FortIO::Namelist.parse(input)
154
+ is_asserted_by { nml.has_key? :example }
155
+ is_asserted_by { nml[:example].is_a? Hash }
156
+ is_asserted_by { nml[:example].keys.size == 4 }
157
+ is_asserted_by { nml[:example].keys == [:a,:b,:c,:d] }
158
+ is_asserted_by { nml[:example].values == [1,2,3,4] }
159
+ end
160
+
161
+
162
+ end
metadata CHANGED
@@ -1,21 +1,38 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fortio-namelist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroki Motoyoshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-22 00:00:00.000000000 Z
12
- dependencies: []
13
- description: " A library for reading/writing fortran namelist file\n"
11
+ date: 2021-06-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: racc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ description: " This is a Ruby library for reading and writing Fortran's namelist.
28
+ \n This library allows you to read a namelist string as a Hash object, \n or dump
29
+ a Hash object to a namelist string.\n"
14
30
  email: ''
15
31
  executables: []
16
32
  extensions: []
17
33
  extra_rdoc_files: []
18
34
  files:
35
+ - NOTE.md
19
36
  - README.md
20
37
  - Rakefile
21
38
  - fortio-namelist.gemspec
@@ -23,6 +40,12 @@ files:
23
40
  - lib/fortio-namelist/fortran_namelist.rb
24
41
  - lib/fortio-namelist/fortran_namelist.tab.rb
25
42
  - lib/fortio-namelist/fortran_namelist.y
43
+ - spec/array_spec.rb
44
+ - spec/dump_spec.rb
45
+ - spec/empty_spec.rb
46
+ - spec/identifier_spec.rb
47
+ - spec/scalar_spec.rb
48
+ - spec/structure_spec.rb
26
49
  homepage: https://github.com/himotoyoshi/fortio-namelist
27
50
  licenses:
28
51
  - MIT
@@ -35,7 +58,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
35
58
  requirements:
36
59
  - - ">="
37
60
  - !ruby/object:Gem::Version
38
- version: 1.8.1
61
+ version: 2.4.0
39
62
  required_rubygems_version: !ruby/object:Gem::Requirement
40
63
  requirements:
41
64
  - - ">="