arrow_test 0.0.1

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 (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/arrow_test.rb +42 -0
  3. data/test_arrow_test.rb +23 -0
  4. metadata +58 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ab80fb2ab081c38e14d753204fe4fc886959df00
4
+ data.tar.gz: 0fec4258fb1605fdf9f1b3b7c9150b3fbfe9540c
5
+ SHA512:
6
+ metadata.gz: a542a1596a9d11dedd585bd572b63f9dd4698c0291c5f4b985f88d49fa6505872bb0b40cdbc1338c462ea78b5a0a9e8262b64c84c6a2e677da4a0241ff96a3db
7
+ data.tar.gz: d07eef93af3f466c51e03b2fda5360096fb0693b37035de6af23cbf6f1717aa17ecef515eee6636ec8a461bba82adbd30da65f5da6754e4153c455ccd4b24eed
data/lib/arrow_test.rb ADDED
@@ -0,0 +1,42 @@
1
+ require 'colorize'
2
+
3
+ def helper_arrow_test(lines, verbose=false)
4
+ messages = []
5
+ arrow_regex = Regexp.new('\ *\#\ *\-\ *\>\ *')
6
+ thick_arrow_regex = Regexp.new('\ *\#\ *\=\ *\>\ *')
7
+ lines
8
+ .select{|line| arrow_regex.match(line) || thick_arrow_regex.match(line)}
9
+ .each do |line|
10
+ expression = line.split('#').first.strip
11
+ result = line.split('#').last.sub("\n", '').sub("-",'').sub(">",'').sub('=','').strip
12
+ got = eval(expression)
13
+ actual = eval(result)
14
+ if got != actual
15
+ messages.push <<END
16
+ ERROR:
17
+ EXECUTING: #{expression}
18
+ EXPECTED: #{result}
19
+ INSTEAD GOT: #{got}\n\n
20
+ END
21
+ elsif verbose
22
+ messages.push <<END
23
+ CORRECT:
24
+ EXECUTING: #{expression}
25
+ REALLY_IS: #{got}\n\n
26
+ END
27
+ end
28
+ end
29
+ messages
30
+ end
31
+
32
+ def arrow_test(filename=$0, verbose=false)
33
+ puts helper_arrow_test(IO.foreach(filename).to_a, verbose)
34
+ end
35
+
36
+ if __FILE__ == $0
37
+ 1 #-> 1
38
+ 1 + 1 #-> 3
39
+ "hello".reverse #-> "oleh"
40
+
41
+ arrow_test($0, true)
42
+ end
@@ -0,0 +1,23 @@
1
+ require 'test/unit'
2
+ require_relative 'lib/arrow_test'
3
+
4
+ class ArrowTestTest < Test::Unit::TestCase
5
+ def test_empty
6
+ assert(helper_arrow_test(['1 # -> 1']) == [], 'Empty is returned for no fails.')
7
+ end
8
+
9
+ def test_wrong_math
10
+ result = ["ERROR:\n EXECUTING: 1 + 1\n EXPECTED: 3\n INSTEAD GOT: 2\n\n\n"]
11
+ assert(helper_arrow_test(['1 + 1 # -> 3']) == result, 'Wrong math is reported.')
12
+ end
13
+
14
+ def test_verbose_output
15
+ result = ["CORRECT:\n EXECUTING: 1\n REALLY_IS: 1\n\n\n"]
16
+ assert(helper_arrow_test(['1 # -> 1'], verbose=true) == result, "Verbose returns also correct expressions")
17
+ end
18
+
19
+ def test_thick_line_with_spaces
20
+ assert(helper_arrow_test(['1 # => 1']) == [], 'Thick line also works.')
21
+ end
22
+ end
23
+
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: arrow_test
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Caridorc Tergilti
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |2
14
+ `Vigorous testing is coincise`
15
+
16
+ This gem allows coincise testing, even shorter than docctest.
17
+
18
+ It also adds minimal overhead to your file!
19
+
20
+ An example usage shows how little typing is required:
21
+
22
+ require 'arrow_test'
23
+ 1 + 1 -> 3
24
+ arrow_test
25
+
26
+ And you are done! Running the above will show you the error.
27
+ email: riki100024@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - lib/arrow_test.rb
33
+ - test_arrow_test.rb
34
+ homepage: http://rubygems.org/gems/arrow_test
35
+ licenses:
36
+ - MIT
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 2.2.2
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Allows coincise testing.
58
+ test_files: []