-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
maliciousness_test.rb
116 lines (94 loc) · 4.61 KB
/
maliciousness_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
require "test_helper"
class Mathematical::MaliciousnessTest < Test::Unit::TestCase
def test_it_does_not_error_on_unrecognized_commands
render = Mathematical.new
output = nil
# In mtex2MML, we raise a ParseError, but Mathematical suppresses it and returns the string.
assert_nothing_raised { output = render.render('$not__thisisnotreal$') }
assert output == '$not__thisisnotreal$'
end
def test_it_does_not_blow_up_on_bad_arguments
# need to pass a hash here
assert_raise TypeError do
render = Mathematical.new("not a hash")
end
# need to pass a string here
render = Mathematical.new
assert_raise TypeError do
Mathematical.new.render(123)
end
end
def test_it_does_not_blow_up_on_bad_options
assert_raise TypeError do
render = Mathematical.new({:ppi => "not a number"})
end
assert_raise TypeError do
render = Mathematical.new({:zoom => "not a number"})
end
assert_raise TypeError do
render = Mathematical.new({:maxsize => "not a number"})
end
assert_raise TypeError do
render = Mathematical.new({:maxsize => -23})
end
assert_raise TypeError do
render = Mathematical.new({:maxsize => 5.3})
end
assert_raise TypeError do
render = Mathematical.new({:format => 123})
end
assert_raise TypeError do
render = Mathematical.new({:format => "something amazing"})
end
assert_raise Mathematical::MaxsizeError do
render = Mathematical.new({:maxsize => 2})
render.render('$a \ne b$')
end
assert_nothing_raised RangeError do
render = Mathematical.new({:maxsize => 2147483647}) # signed long max
render.render('$a \ne b$')
end
assert_raise RangeError do
render = Mathematical.new({ :maxsize => 4_294_967_295 }) # unsigned long max
render.render('$a \ne b$')
end
end
def test_it_does_not_blow_up_on_bad_input
assert_raise TypeError do
Mathematical.new.render(23)
end
assert_raise ArgumentError do
Mathematical.new.render('No dollars')
end
assert_raise ArgumentError do
array = %w(foof poof)
Mathematical.new.render(array)
end
assert_raise ArgumentError do
array = ['$foof$', nil, '$poof$']
Mathematical.new.render(array)
end
end
def test_it_returns_unmodified_string_for_max_parsing
render = Mathematical.new
output = nil
# Much like above, this fails in mtx2MML, but should do nothing here
text = '$\Huge \sqrt\sqrt\sqrt\sqrt\sqrt\sqrt\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}'
assert_nothing_raised { output = render.render(text) }
assert output == text
end
def test_it_parses_all_possible_array_elements
render = Mathematical.new
array = ['$foof$', '$/this___istotallyfake$', '$poof$']
output = nil
_, err = capture_subprocess_io do
output = render.render(array)
end
assert_equal 3, output.length
assert_equal Hash, output.first.class
assert_equal Hash, output.last.class
assert_equal '$/this___istotallyfake$', output[1]
# array errors output to STDERR
assert_match /Failed to parse mtex: \$\/this___istotallyfake\$/, err
end
end