Skip to content

Commit 8ea6e73

Browse files
committed
add more testcases: concern_spec, encryptable_spec, and time_item_spec.cr
1 parent e20a72b commit 8ea6e73

File tree

3 files changed

+391
-0
lines changed

3 files changed

+391
-0
lines changed

spec/concern_spec.cr

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
require "./spec_helper"
2+
3+
module M3U8
4+
include Concern
5+
6+
describe Concern do
7+
describe "parse_attributes" do
8+
{
9+
{
10+
"Key=Value",
11+
{
12+
"Key" => "Value",
13+
},
14+
},
15+
{
16+
"Key=\"Quoted Value\"",
17+
{
18+
"Key" => "Quoted Value",
19+
},
20+
},
21+
{
22+
"Key1=,Key2,=Value",
23+
{
24+
"Key1" => "",
25+
},
26+
},
27+
}.each do |(format, params)|
28+
attributes = parse_attributes(format)
29+
30+
it "hash result" do
31+
attributes.should eq params
32+
end
33+
end
34+
end
35+
36+
describe "parse_client_attributes" do
37+
{
38+
{
39+
{
40+
"X-CUSTOM" => "Client Attributes",
41+
"CUSTOM" => "Not Client Attributes",
42+
},
43+
{
44+
"X-CUSTOM" => "Client Attributes",
45+
},
46+
},
47+
}.each do |(options, params)|
48+
attributes = parse_client_attributes(options)
49+
50+
it "hash result" do
51+
attributes.should eq params
52+
end
53+
end
54+
end
55+
56+
describe "parse_token" do
57+
{
58+
{
59+
"42",
60+
42,
61+
},
62+
{
63+
"42.3",
64+
42.3,
65+
},
66+
{
67+
"true",
68+
true,
69+
},
70+
{
71+
"false",
72+
false,
73+
},
74+
{
75+
"",
76+
"",
77+
},
78+
{
79+
"test",
80+
"test",
81+
},
82+
}.each do |(format, params)|
83+
token = parse_token(format)
84+
85+
it "token result" do
86+
token.should eq params
87+
end
88+
end
89+
end
90+
91+
describe "parse_resolution" do
92+
{
93+
{
94+
"1280x720",
95+
{
96+
width: 1280,
97+
height: 720,
98+
},
99+
},
100+
{
101+
"1280.0x720.0",
102+
{
103+
width: 1280,
104+
height: 720,
105+
},
106+
},
107+
{
108+
"1280",
109+
{
110+
width: 1280,
111+
height: nil,
112+
},
113+
},
114+
{
115+
"axb",
116+
{
117+
width: nil,
118+
height: nil,
119+
},
120+
},
121+
{
122+
"ab",
123+
{
124+
width: nil,
125+
height: nil,
126+
},
127+
},
128+
{
129+
"",
130+
{
131+
width: nil,
132+
height: nil,
133+
},
134+
},
135+
{
136+
nil,
137+
{
138+
width: nil,
139+
height: nil,
140+
},
141+
},
142+
}.each do |(format, params)|
143+
resolution = parse_resolution(format)
144+
145+
it "width" do
146+
resolution[:width].should eq params[:width]?
147+
end
148+
149+
it "height" do
150+
resolution[:height].should eq params[:height]?
151+
end
152+
end
153+
end
154+
155+
describe "parse_frame_rate" do
156+
{
157+
{
158+
"29.97",
159+
BigDecimal.new(29.97),
160+
},
161+
{
162+
"0",
163+
nil,
164+
},
165+
{
166+
nil,
167+
nil,
168+
},
169+
}.each do |(format, params)|
170+
frame_rate = parse_frame_rate(format)
171+
172+
it "frame_rate result" do
173+
frame_rate.should eq params
174+
end
175+
end
176+
end
177+
178+
describe "parse_yes_no" do
179+
{
180+
{
181+
true,
182+
"YES",
183+
},
184+
{
185+
false,
186+
"NO",
187+
},
188+
{
189+
nil,
190+
nil,
191+
},
192+
}.each do |(format, params)|
193+
yes_no = parse_yes_no(format)
194+
195+
it "yes_no result" do
196+
yes_no.should eq params
197+
end
198+
end
199+
end
200+
201+
describe "parse_boolean" do
202+
{
203+
{
204+
"true",
205+
true,
206+
},
207+
{
208+
"YES",
209+
true,
210+
},
211+
{
212+
"True",
213+
true,
214+
},
215+
{
216+
"false",
217+
false,
218+
},
219+
{
220+
"No",
221+
false,
222+
},
223+
{
224+
"maybe",
225+
nil,
226+
},
227+
{
228+
nil,
229+
nil,
230+
},
231+
}.each do |(format, params)|
232+
boolean = parse_boolean(format)
233+
234+
it "boolean result" do
235+
boolean.should eq params
236+
end
237+
end
238+
end
239+
end
240+
end

spec/encryptable_spec.cr

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
require "./spec_helper"
2+
3+
module M3U8
4+
include Encryptable
5+
6+
class DummyEncryptable
7+
include Encryptable
8+
end
9+
10+
describe Encryptable do
11+
describe "expand namedtuple" do
12+
it "full options" do
13+
options = {
14+
method: "AES-128",
15+
uri: "http://test.key",
16+
iv: "D512BBF",
17+
key_format: "identity",
18+
key_format_versions: "1/3",
19+
}
20+
expected = %(METHOD=AES-128,URI="http://test.key",IV=D512BBF,KEYFORMAT="identity",KEYFORMATVERSIONS="1/3")
21+
22+
DummyEncryptable.new(**options).attributes_to_s.should eq expected
23+
end
24+
25+
it "partial options" do
26+
options = {
27+
method: "AES-128",
28+
uri: "http://test.key",
29+
}
30+
expected = %(METHOD=AES-128,URI="http://test.key")
31+
32+
DummyEncryptable.new(**options).attributes_to_s.should eq expected
33+
end
34+
end
35+
36+
describe "convert_key" do
37+
it "raise if METHOD not provided" do
38+
expect_raises(KeyError) do
39+
Encryptable.convert_key({"URI" => "http://test.key"})
40+
end
41+
end
42+
end
43+
44+
{
45+
{
46+
{
47+
method: "AES-128",
48+
uri: "http://test.key",
49+
iv: "D512BBF",
50+
key_format: "identity",
51+
key_format_versions: "1/3",
52+
},
53+
{
54+
"METHOD" => "AES-128",
55+
"URI" => "http://test.key",
56+
"IV" => "D512BBF",
57+
"KEYFORMAT" => "identity",
58+
"KEYFORMATVERSIONS" => "1/3",
59+
},
60+
%(METHOD=AES-128,URI="http://test.key",IV=D512BBF,KEYFORMAT="identity",KEYFORMATVERSIONS="1/3"),
61+
},
62+
{
63+
{
64+
method: "AES-128",
65+
uri: "http://test.key",
66+
},
67+
{
68+
"METHOD" => "AES-128",
69+
"URI" => "http://test.key",
70+
},
71+
%(METHOD=AES-128,URI="http://test.key"),
72+
},
73+
{
74+
{
75+
method: "NONE",
76+
},
77+
{
78+
"METHOD" => "NONE",
79+
},
80+
%(METHOD=NONE),
81+
},
82+
}.each do |(params, params_h, format)|
83+
item = DummyEncryptable.new(params)
84+
item_namedtuple = Encryptable.convert_key(params_h)
85+
86+
pending "hash" do
87+
DummyEncryptable.new(params.to_h).attributes_to_s.should eq format
88+
end
89+
90+
describe "initialize" do
91+
assets_attributes item, params
92+
end
93+
94+
describe "convert_key" do
95+
assets_symbol_attributes item_namedtuple, params
96+
end
97+
98+
it "attributes_to_s" do
99+
item.attributes_to_s.should eq format
100+
end
101+
end
102+
end
103+
end
104+
105+
private def assets_attributes(item, params)
106+
it "method" do
107+
item.method.should eq params[:method]
108+
end
109+
110+
it "uri" do
111+
item.uri.should eq params[:uri]?
112+
end
113+
114+
it "iv" do
115+
item.iv.should eq params[:iv]?
116+
end
117+
118+
it "key_format" do
119+
item.key_format.should eq params[:key_format]?
120+
end
121+
122+
it "key_format_versions" do
123+
item.key_format_versions.should eq params[:key_format_versions]?
124+
end
125+
end
126+
127+
private def assets_symbol_attributes(item, params)
128+
it "method" do
129+
item[:method].should eq params[:method]
130+
end
131+
132+
it "uri" do
133+
item[:uri].should eq params[:uri]?
134+
end
135+
136+
it "iv" do
137+
item[:iv].should eq params[:iv]?
138+
end
139+
140+
it "key_format" do
141+
item[:key_format].should eq params[:key_format]?
142+
end
143+
144+
it "key_format_versions" do
145+
item[:key_format_versions].should eq params[:key_format_versions]?
146+
end
147+
end

spec/time_item_spec.cr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ module M3U8
2323
{time: Time.iso8601("2010-02-19T14:54:23.031Z")},
2424
"#EXT-X-PROGRAM-DATE-TIME:2010-02-19T14:54:23.031Z",
2525
},
26+
{
27+
{time: Time.iso8601("2010-02-19T14:54:23.031+08:00")},
28+
"#EXT-X-PROGRAM-DATE-TIME:2010-02-19T14:54:23.031Z",
29+
},
2630
}.each do |(params, format)|
2731
item = TimeItem.new(params)
2832

0 commit comments

Comments
 (0)