citrus_test 0.1.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 (6) hide show
  1. data/README.md +35 -0
  2. data/UNLICENSE +24 -0
  3. data/lib/citrus_test.rb +89 -0
  4. data.tar.gz.sig +0 -0
  5. metadata +114 -0
  6. metadata.gz.sig +3 -0
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ citrus_test
2
+ ===========
3
+
4
+ citrus_test makes it easier to test Citrus grammars.
5
+
6
+ Quick Start
7
+ -----------
8
+
9
+ require 'citrus_test'
10
+
11
+ # citrus_test expects all your Citrus grammars to be located in grammar_dir.
12
+ # The path grammar_dir is set to is relative to the directory that the source
13
+ # file that set it is in. (If you're using irb, use an absolute path.)
14
+ GrammarTest.grammar_dir = "../grammars/"
15
+
16
+ # What you name your class is important. For example, this class will use the
17
+ # grammar located at ../grammars/nahuatal_language.citrus. The name of your
18
+ # class *must* end in Test.
19
+ class NahuatalLanguageTest < GrammarTest
20
+ def test_possession
21
+ # The parse() method returns the .value of the result of parsing.
22
+ possessed_house = parse(:possession, "no-kal")
23
+ assert_equal('house', possessed_house)
24
+
25
+ # This asserts that:
26
+ # _ = parse(:possession, "no-kal")
27
+ # _ # => "house"
28
+ # _.possessor # => "me"
29
+ assert_parses(:possession, "no-kal", "house", possessor: "me")
30
+
31
+ # deny_parses() does the opposite.
32
+ deny_parses(:possession, "kal-li")
33
+ end
34
+ end
35
+
data/UNLICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org/>
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env ruby
2
+ require 'citrus'
3
+ require 'test/unit'
4
+
5
+ class GrammarTest < Test::Unit::TestCase
6
+ # This is not a test!
7
+ @@test_suites[GrammarTest] = false # Yes, this is undocumented. :x
8
+
9
+ class << self
10
+ attr_reader :grammar_dir
11
+ # gd is considered relative to the directory of the caller's SOURCE CODE.
12
+ def grammar_dir=(gd)
13
+ caller_dir = File.dirname(/\A(.*?):\d+:in `.*'\z/.match(caller[0])[1])
14
+ class_variable_set(:@@grammar_dir, File.absolute_path(gd, caller_dir))
15
+ end
16
+ end
17
+
18
+ # Set the name of the grammar our subclass uses on the basis of its mangled
19
+ # name.
20
+ def self.inherited(subclass) # :nodoc:
21
+ if subclass.name =~ /\ATest([A-Z_][A-Za-z_]*)\z/
22
+ class_variable_set(:@@grammar, $1)
23
+
24
+ super
25
+ else
26
+ raise SyntaxError.new("give your class a proper name")
27
+ end
28
+ end
29
+
30
+ # Convert a camel-cased string to an underscored one. (e.g.
31
+ # "SatanSatanLendMeADollar" becomes "satan_satan_lend_me_a_dollar")
32
+ def mangle_class_name(name) # :nodoc:
33
+ unless name =~ /\A[A-Z_][A-Za-z_]*\z/
34
+ raise "#{name} doesn't look like a valid class name"
35
+ end
36
+
37
+ name.scan(/[A-Z_][a-z_]*/).map(&:downcase).join("_")
38
+ end
39
+
40
+ # Load the grammar file ../grammars/{@@grammar}.citrus
41
+ def setup
42
+ grammar_file = "#{mangle_class_name(@@grammar)}.citrus"
43
+ Citrus.load( File.join(@@grammar_dir, grammar_file) )
44
+ end
45
+
46
+ # Get a specific rule from the grammar.
47
+ def rule(name)
48
+ @rules ||= {}
49
+ @rules[@@grammar] ||= self.class.const_get(@@grammar).rule(name)
50
+ end
51
+
52
+ # Parse input according to rule.
53
+ def parse(rule, input)
54
+ rule(rule).parse(input).value
55
+ end
56
+
57
+ # Assert that rule parses str into val, returning val (actually, the return
58
+ # value of parse(rule, str)) if the assertion passed. Additionally, assert
59
+ # that value has every attribute specified in attributes, and that they have
60
+ # the value specified.
61
+ def assert_parses(rule, str, val, attributes={})
62
+ msg ||= "#{@@grammar}.#{rule} failed to parse #{str.inspect} properly"
63
+
64
+ ret = nil
65
+ assert_nothing_raised(msg) do
66
+ ret = parse(rule, str)
67
+ assert_equal(ret, val, msg)
68
+ end
69
+
70
+ attributes.each do |attr, expected_val|
71
+ assert(ret.respond_to?(attr), "#{attr} doesn't exist")
72
+ _ = "An exception was raised when fetching the #{attr} attribute"
73
+ assert_nothing_raised(_) do
74
+ _ = "#{attr} attribute has an unexpected value"
75
+ assert_equal(expected_val, ret.send(attr), _)
76
+ end
77
+ end
78
+
79
+ ret
80
+ end
81
+
82
+ # Assert that rule raises Citrus::ParseError. (By default, msg is
83
+ # "#{@@grammar}.#{rule} parsed #{str.inspect} when it shouldn't have.")
84
+ def deny_parses(rule, str, msg=nil)
85
+ msg ||= "#{@@grammar}.#{rule} parsed #{str.inspect} when it shouldn't have"
86
+ assert_raises(Citrus::ParseError, msg){ rule(rule).parse(str) }
87
+ end
88
+ end
89
+
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: citrus_test
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
+ platform: ruby
11
+ authors:
12
+ - katmagic
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain:
16
+ - |
17
+ -----BEGIN CERTIFICATE-----
18
+ MIIDQDCCAiigAwIBAgIBADANBgkqhkiG9w0BAQUFADBGMRgwFgYDVQQDDA90aGUu
19
+ bWFnaWNhbC5rYXQxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixk
20
+ ARkWA2NvbTAeFw0xMTA4MjEyMjMyMDFaFw0xMjA4MjAyMjMyMDFaMEYxGDAWBgNV
21
+ BAMMD3RoZS5tYWdpY2FsLmthdDEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYK
22
+ CZImiZPyLGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
23
+ pBt20nwjs5W03djpRN6FAbpiio286NHMTk6HhmjV6GZKOi5ZUX5onTnKUg2Vc35z
24
+ /nK+aIPReyRfBgIcfSjhoXh1A1Dp+2laNgTtU/3eMupruatgORAPCSaG9Ns+HSyR
25
+ vySbz1QUrwvlvF0qkhhApNQ6dsLl2LMOV3QcluY+Y3CVccOWOSHdQcnAbPuzM9Hf
26
+ 4ChI4OGL7+DwLA5OK2S5uewRAa2iLkJSN0WugnQlJqMT59GRaqTDOtnYQpiyKEBy
27
+ QjVPO4LNk7iDsJP22YBrveIzm8/YYRBTU4LTHMEMOyCszrYqD2S1Lwp2rtCJzQCl
28
+ BA0LtBKrZl5mwZm7qyj+TwIDAQABozkwNzAJBgNVHRMEAjAAMB0GA1UdDgQWBBSm
29
+ s5arhjp61kmGl6wsmLYkqerdqDALBgNVHQ8EBAMCBLAwDQYJKoZIhvcNAQEFBQAD
30
+ ggEBAA6cQNQMOPRy4yrj7Nh5Mb9qq8t/8ho/JQvjzVof9qRd+kfKrOoOhXfEO+Rm
31
+ sWcaOnBCVC4DnZuNDSLygVhCDtMnHjg/JsfO/GBF/QlNTJOO1jkoQiS6w0KARlBm
32
+ cpXaWg/oMtXJ2PaUga6WkNeXYf9Mad36P4yuGQScjs+WkUUy7DNZvTGReIcCWOR8
33
+ jteSvvCMobQKGr2DfFOU9Jiddh2FPpz/KOM2ijzwsVNUMUr7R58LoCnQZrZ/YaRW
34
+ ob6QnVgwqu5SUAKQxlFJ/aKlPMj735z8EogaZC1ZHgg3vkgGGyu57N/8BDDG0TzC
35
+ Zn3u2leVae/fJ03zYGArhuJKPgc=
36
+ -----END CERTIFICATE-----
37
+
38
+ date: 2011-08-22 00:00:00 -04:00
39
+ default_executable:
40
+ dependencies:
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ prerelease: false
44
+ requirement: &id001 !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ segments:
50
+ - 0
51
+ version: "0"
52
+ type: :development
53
+ version_requirements: *id001
54
+ - !ruby/object:Gem::Dependency
55
+ name: citrus
56
+ prerelease: false
57
+ requirement: &id002 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ type: :runtime
66
+ version_requirements: *id002
67
+ description: citrus_test makes it easier to test Citrus grammars.
68
+ email: the.magical.kat@gmail.com
69
+ executables: []
70
+
71
+ extensions: []
72
+
73
+ extra_rdoc_files: []
74
+
75
+ files:
76
+ - lib/citrus_test.rb
77
+ - UNLICENSE
78
+ - README.md
79
+ has_rdoc: true
80
+ homepage: https://github.com/katmagic/citrus_test
81
+ licenses:
82
+ - Public Domain
83
+ post_install_message:
84
+ rdoc_options: []
85
+
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ segments:
94
+ - 1
95
+ - 9
96
+ - 2
97
+ version: 1.9.2
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ requirements: []
107
+
108
+ rubyforge_project: citrus_test
109
+ rubygems_version: 1.3.7
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: citrus_test makes it easier to test Citrus grammars.
113
+ test_files: []
114
+
metadata.gz.sig ADDED
@@ -0,0 +1,3 @@
1
+ o�~ē�_y�hw�"=�L����N<ɠ\�Y
2
+ ,���x���̿��#�8#y�H�b���a�t�8�c�$�m������66q��C(!��W��`��~�+���r�$��r9e�|��/b�I�ң�
3
+ �=Cy&�詇8˔W1c���돂8��#���/�ҷn���)�!u �7�|Vvgq�8G>�'v��z�T��!����Z޹9�[������U�iȇ��v1�����l