mathematical 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7920616d037c8cdab3ade36bceda055362a6de9
4
- data.tar.gz: a6d2688b1275203704cf01146a952ee7391c4d76
3
+ metadata.gz: 4c820da257090af3286f7e4756f79ce1aece737d
4
+ data.tar.gz: d2f998fbdd90b00510d0a5ac678af9397fa00dd8
5
5
  SHA512:
6
- metadata.gz: 54a36429dd2a1bd98712ee5a194ef07396a8b76404894d9d3260ca0597b46896a86c97ab6f6664887c15c101dac1c49417880745c55c97ded3672e61390dbb2c
7
- data.tar.gz: 51fdd320022dd0555be2a3141b7a2de65d5c7c076bd441565da36a61e3ba2a77f172e479e104367b268c3983cd362e170f7dda48a1624971d95bc0ff30b94890
6
+ metadata.gz: 643d66def8e1670019d4a9bdad47d3914fb0e09136790e6349e5088a2dcda5db606e81da6480f92c23dc0887b3b10fa2596c28eb31b53420d38300fec0b729be
7
+ data.tar.gz: fedb115fd8b874671d9dfaa43004e89d06640ea3f0288ac3c939d8bff4418c0b58c0e7dc07e89c04058f8367a6c2a807e2ed20a32b3225827ba7493201e57b23
data/README.md CHANGED
@@ -48,7 +48,7 @@ The output will be a hash, with keys that depend on the format you want:
48
48
  * `:data`: the original invalid LaTeX
49
49
  * `:error`: the error class (with message)
50
50
 
51
- **Note**: If you pass in invalid LaTeX, an error is not raised, but a message *is* printed to STDERR, and the original string is returned (not a hash).
51
+ **Note**: If you pass in invalid LaTeX, an error is not raised, but a message *is* printed to STDERR. It is the caller's responsibility to check for `:error` and act on it.
52
52
 
53
53
  ### Array of equations
54
54
 
@@ -75,7 +75,7 @@ Mathematical.new.render(array)
75
75
  [ {:data => "...", :width => ... }, { :data => '$not__thisisnotreal$', :error => "...", {:data => "...", :width => ... }]
76
76
  ```
77
77
 
78
- That is, while the first and last elements are valid LaTeX math, the middle one is not, so the same string is returned. As with single strings, a message is also printed to STDERR.
78
+ That is, while the first and last elements are valid LaTeX math, the middle one is not, so the same string is returned. As with single strings, the error message is printed to STDERR, but not raised.
79
79
 
80
80
  ### Options
81
81
 
@@ -192,6 +192,9 @@ VALUE process(VALUE self, unsigned long maxsize, const char *latex_code, unsigne
192
192
  return result_hash;
193
193
  }
194
194
 
195
+ // `process` can potentially raise a bunch of exceptions, so we need to wrap
196
+ // the call in a rescue. And `rb_rescue` only takes one argument, so we need
197
+ // to pack everything in an array, and then unpack it in `process_helper`.
195
198
  static VALUE process_helper(VALUE data)
196
199
  {
197
200
  VALUE *args = (VALUE *) data;
@@ -221,7 +224,14 @@ static VALUE MATHEMATICAL_process(VALUE self, VALUE rb_Input)
221
224
  case T_STRING: {
222
225
  latex_code = StringValueCStr(rb_Input);
223
226
  latex_size = (unsigned long) strlen(latex_code);
224
- output = process(self, maxsize, latex_code, latex_size);
227
+
228
+ VALUE args[4];
229
+ args[0] = self;
230
+ args[1] = ULONG2NUM(maxsize);
231
+ args[2] = rb_Input;
232
+ args[3] = ULONG2NUM(latex_size);
233
+
234
+ output = rb_rescue(process_helper, args, process_rescue, rb_Input);
225
235
  break;
226
236
  }
227
237
  case T_ARRAY: {
@@ -238,14 +248,12 @@ static VALUE MATHEMATICAL_process(VALUE self, VALUE rb_Input)
238
248
  latex_code = StringValueCStr(math);
239
249
  latex_size = (unsigned long) strlen(latex_code);
240
250
 
241
- // `process` can potentially raise a bunch of exceptions, so we need to wrap
242
- // the call in a rescue. And `rb_rescue` only takes one argument, so we need
243
- // to pack everything in an array, and then unpack it in `process_helper`.
244
- VALUE args[5];
251
+ VALUE args[4];
245
252
  args[0] = self;
246
253
  args[1] = ULONG2NUM(maxsize);
247
254
  args[2] = math;
248
255
  args[3] = ULONG2NUM(latex_size);
256
+
249
257
  hash = rb_rescue(process_helper, args, process_rescue, math);
250
258
 
251
259
  rb_ary_store(output, i, hash);
data/lib/mathematical.rb CHANGED
@@ -33,19 +33,13 @@ class Mathematical
33
33
  def render(maths)
34
34
  maths = validate_content(maths)
35
35
 
36
- begin
37
- result_data = @processer.process(maths)
38
- fail RuntimeError if result_data.nil? || (!result_data.is_a?(Hash) && !result_data.is_a?(Array))
39
-
40
- if result_data.is_a? Array
41
- result_data.map { |d| format_data(d) }
42
- else
43
- format_data(result_data)
44
- end
45
- rescue ParseError, DocumentCreationError, DocumentReadError => e
46
- # an error in the C code, probably a bad TeX parse
47
- $stderr.puts "#{e.message}: #{maths}"
48
- maths
36
+ result_data = @processer.process(maths)
37
+ fail RuntimeError if !result_data.is_a?(Hash) && !result_data.is_a?(Array)
38
+
39
+ if result_data.is_a? Array
40
+ result_data.map { |d| format_data(d) }
41
+ else
42
+ format_data(result_data)
49
43
  end
50
44
  end
51
45
 
@@ -1,3 +1,3 @@
1
1
  class Mathematical
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  end
@@ -7,7 +7,8 @@ class Mathematical::MaliciousnessTest < Test::Unit::TestCase
7
7
  output = nil
8
8
  # In mtex2MML, we raise a ParseError, but Mathematical suppresses it and returns the string.
9
9
  assert_nothing_raised { output = render.render('$not__thisisnotreal$') }
10
- assert output == '$not__thisisnotreal$'
10
+ assert_equal output[:data], '$not__thisisnotreal$'
11
+ assert_equal output[:exception].class, Mathematical::ParseError
11
12
  end
12
13
 
13
14
  def test_it_does_not_blow_up_on_bad_arguments
@@ -25,42 +26,37 @@ class Mathematical::MaliciousnessTest < Test::Unit::TestCase
25
26
 
26
27
  def test_it_does_not_blow_up_on_bad_options
27
28
  assert_raise TypeError do
28
- render = Mathematical.new({:ppi => "not a number"})
29
+ Mathematical.new({:ppi => 'not a number'})
29
30
  end
30
31
 
31
32
  assert_raise TypeError do
32
- render = Mathematical.new({:zoom => "not a number"})
33
+ render = Mathematical.new({:zoom => 'not a number'})
33
34
  end
34
35
 
35
36
  assert_raise TypeError do
36
- render = Mathematical.new({:maxsize => "not a number"})
37
+ Mathematical.new({:maxsize => 'not a number'})
37
38
  end
38
39
 
39
40
  assert_raise TypeError do
40
- render = Mathematical.new({:maxsize => -23})
41
+ Mathematical.new({:maxsize => -23})
41
42
  end
42
43
 
43
44
  assert_raise TypeError do
44
- render = Mathematical.new({:maxsize => 5.3})
45
+ Mathematical.new({:maxsize => 5.3})
45
46
  end
46
47
 
47
48
  assert_raise TypeError do
48
- render = Mathematical.new({:format => 123})
49
+ Mathematical.new({:format => 123})
49
50
  end
50
51
 
51
52
  assert_raise TypeError do
52
- render = Mathematical.new({:format => "something amazing"})
53
+ Mathematical.new({:format => 'something amazing'})
53
54
  end
54
55
 
55
- assert_raise Mathematical::MaxsizeError do
56
- render = Mathematical.new({:maxsize => 2})
57
- render.render('$a \ne b$')
58
- end
59
-
60
- assert_nothing_raised RangeError do
61
- render = Mathematical.new({:maxsize => 2147483647}) # signed long max
62
- render.render('$a \ne b$')
63
- end
56
+ render = Mathematical.new({:maxsize => 2})
57
+ output = render.render '$a \ne b$'
58
+ assert_equal output[:data], '$a \ne b$'
59
+ assert_equal output[:exception].class, Mathematical::MaxsizeError
64
60
 
65
61
  assert_raise RangeError do
66
62
  render = Mathematical.new({ :maxsize => 4_294_967_295 }) # unsigned long max
@@ -94,7 +90,8 @@ class Mathematical::MaliciousnessTest < Test::Unit::TestCase
94
90
  # Much like above, this fails in mtx2MML, but should do nothing here
95
91
  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{\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}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}'
96
92
  assert_nothing_raised { output = render.render(text) }
97
- assert output == text
93
+ assert_equal output[:data], text
94
+ assert_equal output[:exception].class, Mathematical::ParseError
98
95
  end
99
96
 
100
97
  def test_it_parses_all_possible_array_elements
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mathematical
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian