mathematical 1.3.0 → 1.4.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 (74) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +14 -7
  3. data/Rakefile +4 -1
  4. data/ext/mathematical/cairo_callbacks.h +5 -0
  5. data/ext/mathematical/extconf.rb +34 -8
  6. data/ext/mathematical/lasem_overrides.c +32 -3
  7. data/ext/mathematical/lasem_overrides.h +11 -2
  8. data/ext/mathematical/mathematical.c +27 -26
  9. data/ext/mathematical/mathematical.h +5 -1
  10. data/ext/mathematical/mtex2MML/deps/strdup/strdup.c +24 -0
  11. data/ext/mathematical/mtex2MML/deps/strdup/strdup.h +24 -0
  12. data/ext/mathematical/mtex2MML/deps/uthash/utarray.h +1 -0
  13. data/ext/mathematical/mtex2MML/src/{color_definitions.c → colors.c} +2 -3
  14. data/ext/mathematical/mtex2MML/src/colors.h +23 -0
  15. data/ext/mathematical/mtex2MML/src/em.c +99 -0
  16. data/ext/mathematical/mtex2MML/src/em.h +31 -0
  17. data/ext/mathematical/mtex2MML/src/{parse_extras.c → environment.c} +73 -157
  18. data/ext/mathematical/mtex2MML/src/environment.h +85 -0
  19. data/ext/mathematical/mtex2MML/src/{mtex2MML.l → lexer.l} +26 -15
  20. data/ext/mathematical/mtex2MML/src/main.c +31 -10
  21. data/ext/mathematical/mtex2MML/src/mtex2MML.h +19 -7
  22. data/ext/mathematical/mtex2MML/src/{mtex2MML.y → parser.y} +451 -446
  23. data/ext/mathematical/mtex2MML/src/string_extras.c +4 -3
  24. data/ext/mathematical/mtex2MML/src/string_extras.h +7 -7
  25. data/ext/mathematical/mtex2MML/tests/array.c +11 -11
  26. data/ext/mathematical/mtex2MML/tests/basic.c +14 -13
  27. data/ext/mathematical/mtex2MML/tests/clar.c +2 -0
  28. data/ext/mathematical/mtex2MML/tests/clar/fs.h +3 -1
  29. data/ext/mathematical/mtex2MML/tests/clar/sandbox.h +3 -1
  30. data/ext/mathematical/mtex2MML/tests/cornercases.c +3 -2
  31. data/ext/mathematical/mtex2MML/tests/delimiters.c +126 -0
  32. data/ext/mathematical/mtex2MML/tests/deps/file2str/file2str.c +2 -4
  33. data/ext/mathematical/mtex2MML/tests/deps/mkdtemp/mkdtemp.c +151 -0
  34. data/ext/mathematical/mtex2MML/tests/deps/mkdtemp/mkdtemp.h +10 -0
  35. data/ext/mathematical/mtex2MML/tests/deps/trim/trim.c +4 -1
  36. data/ext/mathematical/mtex2MML/tests/env.c +35 -34
  37. data/ext/mathematical/mtex2MML/tests/functions.c +3 -2
  38. data/ext/mathematical/mtex2MML/tests/helpers.c +6 -4
  39. data/ext/mathematical/mtex2MML/tests/helpers.h +2 -2
  40. data/ext/mathematical/mtex2MML/tests/main.c +1 -1
  41. data/ext/mathematical/mtex2MML/tests/maliciousness.c +35 -9
  42. data/ext/mathematical/mtex2MML/tests/mathjax.c +202 -202
  43. data/ext/mathematical/mtex2MML/tests/numbered_equations.c +6 -6
  44. data/ext/mathematical/mtex2MML/tests/performance.c +39 -0
  45. data/lib/mathematical.rb +38 -5
  46. data/lib/mathematical/configuration.rb +19 -0
  47. data/lib/mathematical/validator.rb +17 -31
  48. data/lib/mathematical/version.rb +1 -1
  49. data/mathematical.gemspec +3 -1
  50. data/test/mathematical/basic_test.rb +60 -7
  51. data/test/mathematical/corrections_test.rb +1 -1
  52. data/test/mathematical/delimiters_test.rb +58 -0
  53. data/test/mathematical/fixtures_test.rb +3 -2
  54. data/test/mathematical/maliciousness_test.rb +19 -27
  55. data/test/mathematical/mathjax_test.rb +6 -5
  56. data/test/mathematical/mathml_test.rb +1 -1
  57. data/test/mathematical/multiples_test.rb +1 -1
  58. data/test/mathematical/performance_test.rb +3 -1
  59. data/test/mathematical/png_test.rb +3 -3
  60. data/test/test_helper.rb +4 -1
  61. metadata +35 -21
  62. data/ext/mathematical/lasem/src/lsmdomenumtypes.c +0 -99
  63. data/ext/mathematical/lasem/src/lsmdomenumtypes.h +0 -26
  64. data/ext/mathematical/lasem/src/lsmmathmlenumtypes.c +0 -737
  65. data/ext/mathematical/lasem/src/lsmmathmlenumtypes.h +0 -93
  66. data/ext/mathematical/lasem/src/lsmsvgenumtypes.c +0 -1083
  67. data/ext/mathematical/lasem/src/lsmsvgenumtypes.h +0 -111
  68. data/ext/mathematical/mtex2MML/Makefile +0 -100
  69. data/ext/mathematical/mtex2MML/build/libmtex2MML.a +0 -0
  70. data/ext/mathematical/mtex2MML/build/mtex2MML.h +0 -73
  71. data/ext/mathematical/mtex2MML/src/lex.yy.c +0 -8845
  72. data/ext/mathematical/mtex2MML/src/parse_extras.h +0 -111
  73. data/ext/mathematical/mtex2MML/src/y.tab.c +0 -10178
  74. data/ext/mathematical/mtex2MML/src/y.tab.h +0 -617
@@ -5,7 +5,7 @@
5
5
 
6
6
  static char *fixture_tex;
7
7
  static char *fixture_mml;
8
- static const char *result;
8
+ static char *result;
9
9
 
10
10
  void test_numbered_equations__initialize(void)
11
11
  {
@@ -31,7 +31,7 @@ void test_numbered_equations__single_equation(void)
31
31
  {
32
32
  fixture_tex = read_fixture_tex("numbered_equations/single_equation.txt");
33
33
  fixture_mml = read_fixture_mml("numbered_equations/single_equation.html");
34
- result = mtex2MML_global_parse(fixture_tex, strlen(fixture_tex), 1);
34
+ result = mtex2MML_global_parse(fixture_tex, strlen(fixture_tex), MTEX2MML_DELIMITER_DEFAULT, 1);
35
35
 
36
36
  cl_assert_equal_s(fixture_mml, result);
37
37
  }
@@ -40,7 +40,7 @@ void test_numbered_equations__multiple_equations(void)
40
40
  {
41
41
  fixture_tex = read_fixture_tex("numbered_equations/multiple_equations.txt");
42
42
  fixture_mml = read_fixture_mml("numbered_equations/multiple_equations.html");
43
- mtex2MML_filter(fixture_tex, strlen(fixture_tex));
43
+ mtex2MML_filter(fixture_tex, strlen(fixture_tex), MTEX2MML_DELIMITER_DEFAULT);
44
44
  result = mtex2MML_output();
45
45
 
46
46
  cl_assert_equal_s(fixture_mml, result);
@@ -50,7 +50,7 @@ void test_numbered_equations__single_notag(void)
50
50
  {
51
51
  fixture_tex = read_fixture_tex("numbered_equations/single_notag.txt");
52
52
  fixture_mml = read_fixture_mml("numbered_equations/single_notag.html");
53
- result = mtex2MML_global_parse(fixture_tex, strlen(fixture_tex), 1);
53
+ result = mtex2MML_global_parse(fixture_tex, strlen(fixture_tex), MTEX2MML_DELIMITER_DEFAULT, 1);
54
54
 
55
55
  cl_assert_equal_s(fixture_mml, result);
56
56
  }
@@ -59,7 +59,7 @@ void test_numbered_equations__single_nonumber(void)
59
59
  {
60
60
  fixture_tex = read_fixture_tex("numbered_equations/single_nonumber.txt");
61
61
  fixture_mml = read_fixture_mml("numbered_equations/single_nonumber.html");
62
- result = mtex2MML_global_parse(fixture_tex, strlen(fixture_tex), 1);
62
+ result = mtex2MML_global_parse(fixture_tex, strlen(fixture_tex), MTEX2MML_DELIMITER_DEFAULT, 1);
63
63
 
64
64
  cl_assert_equal_s(fixture_mml, result);
65
65
  }
@@ -68,7 +68,7 @@ void test_numbered_equations__multiple_notag_nonumber(void)
68
68
  {
69
69
  fixture_tex = read_fixture_tex("numbered_equations/multiple_notag_nonumber.txt");
70
70
  fixture_mml = read_fixture_mml("numbered_equations/multiple_notag_nonumber.html");
71
- result = mtex2MML_global_parse(fixture_tex, strlen(fixture_tex), 1);
71
+ result = mtex2MML_global_parse(fixture_tex, strlen(fixture_tex), MTEX2MML_DELIMITER_DEFAULT, 1);
72
72
 
73
73
  cl_assert_equal_s(fixture_mml, result);
74
74
  }
@@ -0,0 +1,39 @@
1
+ #include "clar.h"
2
+ #include "clar_test.h"
3
+ #include "deps/trim/trim.h"
4
+ #include <stdio.h>
5
+ #include <string.h>
6
+
7
+ static char *fixture_tex;
8
+ static char *fixture_mml;
9
+ static char *result;
10
+
11
+ void test_performance__initialize(void)
12
+ {
13
+ global_test_counter++;
14
+ }
15
+
16
+ void test_performance__cleanup(void)
17
+ {
18
+ if (fixture_tex != NULL) {
19
+ free(fixture_tex);
20
+ }
21
+
22
+ if (fixture_mml != NULL) {
23
+ free(fixture_mml);
24
+ }
25
+
26
+ if (result != NULL) {
27
+ free(result);
28
+ }
29
+ }
30
+
31
+ void test_performance__big_file(void)
32
+ {
33
+ fixture_tex = read_fixture_tex("performance/big_file.txt");
34
+ fixture_mml = read_fixture_mml("performance/big_file.html");
35
+ mtex2MML_filter(fixture_tex, strlen(fixture_tex), MTEX2MML_DELIMITER_DEFAULT);
36
+ result = mtex2MML_output();
37
+
38
+ cl_assert_equal_s(fixture_mml, result);
39
+ }
data/lib/mathematical.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'mathematical/mathematical'
2
2
 
3
+ require 'mathematical/configuration'
3
4
  require 'mathematical/corrections'
4
5
  require 'mathematical/validator'
5
6
  require 'mathematical/version'
@@ -15,25 +16,57 @@ class Mathematical
15
16
  :zoom => 1.0,
16
17
  :base64 => false,
17
18
  :maxsize => 0,
18
- :format => :svg
19
+ :format => :svg,
20
+ :delimiter => [:dollar, :double]
19
21
  }
20
22
 
21
23
  XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
22
24
 
23
- def initialize(opts = {})
24
- @config = DEFAULT_OPTS.merge(opts)
25
+ def initialize(options = {})
26
+ @config = DEFAULT_OPTS.merge(options)
25
27
 
26
28
  validate_config(@config)
27
29
 
28
30
  @config[:formatInt] = FORMAT_TYPES.index(@config[:format])
29
31
 
32
+ if @config[:delimiter].is_a?(Symbol)
33
+ @config[:delimiter] = Configuration::Delimiters.to_h[@config[:delimiter]]
34
+ else
35
+ @config[:delimiter] = @config[:delimiter].map do |delim|
36
+ Configuration::Delimiters.to_h[delim]
37
+ end.inject(0, :|)
38
+ end
39
+
30
40
  @processer = Mathematical::Process.new(@config)
31
41
  end
32
42
 
33
- def render(maths)
43
+ def parse(maths)
34
44
  maths = validate_content(maths)
45
+ result_data = @processer.process(maths, RENDER_TYPES.find_index(:parse))
46
+ result(result_data)
47
+ end
48
+ # TODO: deprecate this?
49
+ alias_method :render, :parse
50
+
51
+ def filter(maths)
52
+ maths = validate_content(maths)
53
+ result_data = @processer.process(maths, RENDER_TYPES.find_index(:filter))
54
+ result(result_data)
55
+ end
56
+
57
+ def text_filter(maths)
58
+ maths = validate_content(maths)
59
+ result_data = @processer.process(maths, RENDER_TYPES.find_index(:text_filter))
60
+ result(result_data)
61
+ end
62
+
63
+ def strict_filter(maths)
64
+ maths = validate_content(maths)
65
+ result_data = @processer.process(maths, RENDER_TYPES.find_index(:strict_filter))
66
+ result(result_data)
67
+ end
35
68
 
36
- result_data = @processer.process(maths)
69
+ def result(result_data)
37
70
  fail RuntimeError if !result_data.is_a?(Hash) && !result_data.is_a?(Array)
38
71
 
39
72
  if result_data.is_a? Array
@@ -0,0 +1,19 @@
1
+ require 'ruby-enum'
2
+
3
+ class Configuration
4
+ class Delimiters
5
+ include Ruby::Enum
6
+
7
+ define :default, 0
8
+ define :dollar, 1
9
+ define :double, 2
10
+ define :parens, 4
11
+ define :brackets, 8
12
+
13
+ def self.option_exists?(option)
14
+ unless Delimiters.keys.include?(option)
15
+ fail TypeError, "delimiter type does not exist: #{option}"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,52 +1,38 @@
1
1
  class Mathematical
2
2
  module Validator
3
- # explanation can be found at http://git.io/vJRBj
4
- DOLLAR_MATCHER = /\A(?<!\\)(?:((?<!\$)\${1,2}(?!\$))(.*?(\g<1>)?.*?)(?<!\\)(?(1)(?<!\$)\1(?!\$)))\z/xm
5
3
 
6
4
  FORMAT_TYPES = [:svg, :png, :mathml].freeze
5
+ RENDER_TYPES = [:parse, :filter, :text_filter, :strict_filter].freeze
7
6
 
8
7
  def validate_config(config)
9
8
  fail(TypeError, 'maxsize must be an integer!') unless config[:maxsize].is_a? Fixnum
10
9
  fail(TypeError, 'maxsize cannot be less than 0!') if config[:maxsize] < 0
11
10
  fail(TypeError, 'format must be a symbol!') unless config[:format].is_a? Symbol
12
11
  fail(TypeError, "format type must be one of the following formats: #{FORMAT_TYPES.join(', ')}") unless FORMAT_TYPES.include?(config[:format])
13
- end
12
+ if config[:delimiter].is_a?(Symbol)
13
+ Configuration::Delimiters.option_exists?(config[:delimiter])
14
+ elsif config[:delimiter].is_a?(Array)
15
+ config[:delimiter] = [nil] if config[:delimiter].empty?
14
16
 
15
- def validate_content(maths)
16
- if !maths.is_a?(String) && !maths.is_a?(Array)
17
- fail(TypeError, 'input must be a string or an array!')
18
- end
19
-
20
- if maths.is_a? String
21
- validate_string(maths)
17
+ config[:delimiter].each do |delim|
18
+ Configuration::Delimiters.option_exists?(delim)
19
+ end
22
20
  else
23
- validate_array(maths)
24
- end
25
- end
26
-
27
- def validate_string(maths)
28
- maths = maths.strip
29
- unless valid_math_string(maths)
30
- fail(ArgumentError, 'input must be in tex format (`$...$` or `$$...$$`)!')
21
+ fail(TypeError, 'delimiter type must be a valid symbol or array of symbols')
31
22
  end
32
-
33
- maths
34
23
  end
35
24
 
36
- def validate_array(maths)
37
- maths.map do |m|
38
- unless m.is_a?(String)
39
- fail(ArgumentError, 'every element in array must be a string in tex format (`$...$` or `$$...$$`)!')
40
- end
41
- validate_string(m)
25
+ def validate_content(maths)
26
+ if maths.is_a? Array
27
+ maths.map { |m| validate_string(m) }
28
+ else
29
+ validate_string(maths)
42
30
  end
43
-
44
- maths
45
31
  end
46
32
 
47
- def valid_math_string(maths)
48
- maths =~ DOLLAR_MATCHER
33
+ def validate_string(maths)
34
+ fail(ArgumentError, 'input must be string!') unless maths.is_a?(String)
35
+ maths.strip
49
36
  end
50
-
51
37
  end
52
38
  end
@@ -1,3 +1,3 @@
1
1
  class Mathematical
2
- VERSION = '1.3.0'
2
+ VERSION = '1.4.0'
3
3
  end
data/mathematical.gemspec CHANGED
@@ -22,9 +22,11 @@ Gem::Specification.new do |spec|
22
22
  spec.require_paths = %w(lib ext)
23
23
  spec.extensions = ['ext/mathematical/extconf.rb']
24
24
 
25
+ spec.add_dependency 'ruby-enum', '~> 0.4'
26
+
25
27
  spec.add_development_dependency 'rake', '~> 0.9'
26
28
  spec.add_development_dependency 'rake-compiler', '~> 0.9'
27
- spec.add_development_dependency 'bundler', '~> 1.5'
29
+ spec.add_development_dependency 'bundler', '~> 1.2'
28
30
  spec.add_development_dependency 'minitest', '~> 5.6'
29
31
  spec.add_development_dependency 'math-to-itex', '~> 0.3'
30
32
  spec.add_development_dependency 'nokogiri', '~> 1.6'
@@ -1,7 +1,7 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
+ require 'nokogiri'
2
3
 
3
4
  class Mathematical::BasicTest < MiniTest::Test
4
-
5
5
  def test_it_has_a_version
6
6
  assert Mathematical::VERSION
7
7
  end
@@ -11,13 +11,66 @@ class Mathematical::BasicTest < MiniTest::Test
11
11
  render.render('$\pi$')
12
12
  output = render.render('$\pi$')[:data]
13
13
  assert_equal 1, output.scan(/<svg/).size, 'should only contain one svg'
14
+
15
+ # assert the SVG actually rendered
16
+ doc = Nokogiri::HTML(output)
17
+ assert_empty doc.search(%(//svg[@width='0pt']))
18
+ assert_empty doc.search(%(//svg[@height='0pt']))
14
19
  end
15
20
 
16
- def test_handles_line_breaks
17
- s = "$$x\ny$$"
18
- render = Mathematical.new
19
- output = render.render(s)[:data]
20
- assert_equal 1, output.scan(/<svg/).size, 'should only contain one svg'
21
+ def test_inline
22
+ render = Mathematical.new(:format => :mathml)
23
+
24
+ fixture_tex = File.read(File.join(MTEX2MML_FIXTURES_DIR, 'basic', 'inline.txt'))
25
+ fixture_mml = File.read(File.join(MTEX2MML_FIXTURES_DIR, 'basic', 'inline.html')).strip
26
+ result = render.parse(fixture_tex)
27
+ output = result[:data]
28
+
29
+ assert_equal(fixture_mml, output)
30
+ end
31
+
32
+ def test_block
33
+ render = Mathematical.new(:format => :mathml)
34
+
35
+ fixture_tex = File.read(File.join(MTEX2MML_FIXTURES_DIR, 'basic', 'block.txt'))
36
+ fixture_mml = File.read(File.join(MTEX2MML_FIXTURES_DIR, 'basic', 'block.html')).strip
37
+ result = render.parse(fixture_tex)
38
+ output = result[:data]
39
+
40
+ assert_equal(fixture_mml, output)
41
+ end
42
+
43
+
44
+ def test_filter
45
+ render = Mathematical.new(:format => :mathml)
46
+
47
+ fixture_tex = File.read(File.join(MTEX2MML_FIXTURES_DIR, 'basic', 'filter.txt'))
48
+ fixture_mml = File.read(File.join(MTEX2MML_FIXTURES_DIR, 'basic', 'filter.html')).strip
49
+ result = render.filter(fixture_tex)
50
+ output = result[:data]
51
+
52
+ assert_equal(fixture_mml, output)
21
53
  end
22
54
 
55
+ def test_text_filter
56
+ render = Mathematical.new(:format => :mathml)
57
+
58
+ fixture_tex = File.read(File.join(MTEX2MML_FIXTURES_DIR, 'basic', 'text_filter.txt'))
59
+ fixture_mml = File.read(File.join(MTEX2MML_FIXTURES_DIR, 'basic', 'text_filter.html')).strip
60
+ result = render.text_filter(fixture_tex)
61
+ output = result[:data]
62
+
63
+ assert_equal(fixture_mml, output)
64
+ end
65
+
66
+ def test_strict_filter
67
+ render = Mathematical.new(:format => :mathml)
68
+
69
+ fixture_tex = File.read(File.join(MTEX2MML_FIXTURES_DIR, 'basic', 'strict_filter.txt'))
70
+ fixture_mml = File.read(File.join(MTEX2MML_FIXTURES_DIR, 'basic', 'strict_filter.html')).strip
71
+ result = render.strict_filter(fixture_tex)
72
+ output = result[:data]
73
+
74
+ assert_equal(fixture_mml, output)
75
+ end
23
76
  end
@@ -1,4 +1,4 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
2
 
3
3
  class Mathematical::CorrectionsTest < MiniTest::Test
4
4
 
@@ -0,0 +1,58 @@
1
+ require 'test_helper'
2
+
3
+ class Mathematical::BasicTest < MiniTest::Test
4
+ def test_single_dollar
5
+ render = Mathematical.new(:delimiter => :dollar, :format => :mathml)
6
+
7
+ fixture_tex = "$\\pi$"
8
+ fixture_mml = File.read(File.join(MTEX2MML_FIXTURES_DIR, 'delimiters', 'single_dollar.html')).strip
9
+ result = render.render(fixture_tex)
10
+ output = result[:data]
11
+
12
+ assert_equal(fixture_mml, output)
13
+ end
14
+
15
+ def test_double_dollar
16
+ render = Mathematical.new(:delimiter => :double, :format => :mathml)
17
+
18
+ fixture_tex = "$$\\pi$$"
19
+ fixture_mml = File.read(File.join(MTEX2MML_FIXTURES_DIR, 'delimiters', 'double_dollar.html')).strip
20
+ result = render.render(fixture_tex)
21
+ output = result[:data]
22
+
23
+ assert_equal(fixture_mml, output)
24
+ end
25
+
26
+ def test_parens
27
+ render = Mathematical.new(:delimiter => :parens, :format => :mathml)
28
+
29
+ fixture_tex = "\\(\\pi\\)"
30
+ fixture_mml = File.read(File.join(MTEX2MML_FIXTURES_DIR, 'delimiters', 'parens.html')).strip
31
+ result = render.render(fixture_tex)
32
+ output = result[:data]
33
+
34
+ assert_equal(fixture_mml, output)
35
+ end
36
+
37
+ def test_brackets
38
+ render = Mathematical.new(:delimiter => :brackets, :format => :mathml)
39
+
40
+ fixture_tex = "\\[\\pi\\]"
41
+ fixture_mml = File.read(File.join(MTEX2MML_FIXTURES_DIR, 'delimiters', 'brackets.html')).strip
42
+ result = render.render(fixture_tex)
43
+ output = result[:data]
44
+
45
+ assert_equal(fixture_mml, output)
46
+ end
47
+
48
+ def test_mixed
49
+ render = Mathematical.new(:delimiter => [:brackets, :double], :format => :mathml)
50
+
51
+ fixture_tex = "\\[\\alpha\\] $$\\beta$$"
52
+ fixture_mml = File.read(File.join(MTEX2MML_FIXTURES_DIR, 'delimiters', 'mixed.html')).strip
53
+ result = render.filter(fixture_tex)
54
+ output = result[:data]
55
+
56
+ assert_equal(fixture_mml.strip, output)
57
+ end
58
+ end
@@ -1,4 +1,5 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
+ require 'math-to-itex'
2
3
 
3
4
  class Mathematical::FixturesTest < MiniTest::Test
4
5
  # the same SVGs sometimes get random id values, throwing off the tests
@@ -13,7 +14,7 @@ class Mathematical::FixturesTest < MiniTest::Test
13
14
  source = File.read(before)
14
15
 
15
16
  if ENV['MATHEMATICAL_GENERATE_SAMPLE']
16
- next unless name.match /compliance/
17
+ next unless name.match(/compliance/)
17
18
  write_sample(source)
18
19
  end
19
20
 
@@ -1,4 +1,4 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
2
 
3
3
  class Mathematical::MaliciousnessTest < MiniTest::Test
4
4
 
@@ -19,7 +19,7 @@ class Mathematical::MaliciousnessTest < MiniTest::Test
19
19
 
20
20
  # need to pass a string here
21
21
  render = Mathematical.new
22
- assert_raises TypeError do
22
+ assert_raises ArgumentError do
23
23
  Mathematical.new.render(123)
24
24
  end
25
25
  end
@@ -65,47 +65,39 @@ class Mathematical::MaliciousnessTest < MiniTest::Test
65
65
  end
66
66
 
67
67
  def test_it_does_not_blow_up_on_bad_input
68
- assert_raises TypeError do
69
- Mathematical.new.render(23)
70
- end
71
-
72
68
  assert_raises ArgumentError do
73
- Mathematical.new.render('No dollars')
74
- end
75
-
76
- assert_raises ArgumentError do
77
- Mathematical.new.render('$$x')
69
+ Mathematical.new.render(23)
78
70
  end
79
71
 
80
- assert_raises ArgumentError do
81
- Mathematical.new.render('x$$')
82
- end
72
+ # no delimiters
73
+ assert_equal Mathematical.new.render('x$$')[:exception].class, Mathematical::ParseError
74
+ assert_equal Mathematical.new.filter('$$x')[:exception].class, Mathematical::DocumentCreationError
75
+ assert_equal Mathematical.new.text_filter('No dollars')[:exception].class, Mathematical::DocumentCreationError
83
76
 
84
77
  assert_raises ArgumentError do
85
- Mathematical.new.render('$$x$')
78
+ array = ['$foof$', nil, '$poof$']
79
+ Mathematical.new.render(array)
86
80
  end
87
81
 
88
82
  assert_raises ArgumentError do
89
- Mathematical.new.render('$x$$')
83
+ array = ['$x$', 4]
84
+ Mathematical.new.render(array)
90
85
  end
91
86
 
92
- assert_raises ArgumentError do
93
- Mathematical.new.render('blah blah $x$ blah')
87
+ assert_raises TypeError do
88
+ Mathematical.new({ :delimiter => 'nope' }).render('$P$')
94
89
  end
95
90
 
96
- assert_raises ArgumentError do
97
- array = %w(foof poof)
98
- Mathematical.new.render(array)
91
+ assert_raises TypeError do
92
+ Mathematical.new({ :delimiter => :nope }).render('$P$',)
99
93
  end
100
94
 
101
- assert_raises ArgumentError do
102
- array = ['$foof$', nil, '$poof$']
103
- Mathematical.new.render(array)
95
+ assert_raises TypeError do
96
+ Mathematical.new({ :delimiter => [:dollar, 23] }).render('$P$',)
104
97
  end
105
98
 
106
- assert_raises ArgumentError do
107
- array = ['$x$', 4]
108
- Mathematical.new.render(array)
99
+ assert_raises TypeError do
100
+ Mathematical.new({ :delimiter => [] }).render('$P$',)
109
101
  end
110
102
  end
111
103