citrus_test 0.1-x86-linux
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/README.md +35 -0
- data/UNLICENSE +24 -0
- data/lib/citrus_test.rb +89 -0
- metadata +113 -0
- metadata.gz.sig +0 -0
data.tar.gz.sig
ADDED
Binary file
|
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/>
|
data/lib/citrus_test.rb
ADDED
@@ -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
|
+
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
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
|
+
version: "0.1"
|
9
|
+
platform: x86-linux
|
10
|
+
authors:
|
11
|
+
- katmagic
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain:
|
15
|
+
- |
|
16
|
+
-----BEGIN CERTIFICATE-----
|
17
|
+
MIIDQDCCAiigAwIBAgIBADANBgkqhkiG9w0BAQUFADBGMRgwFgYDVQQDDA90aGUu
|
18
|
+
bWFnaWNhbC5rYXQxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixk
|
19
|
+
ARkWA2NvbTAeFw0xMTA4MjEyMjMyMDFaFw0xMjA4MjAyMjMyMDFaMEYxGDAWBgNV
|
20
|
+
BAMMD3RoZS5tYWdpY2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|
+
|
37
|
+
date: 2011-08-22 00:00:00 -04:00
|
38
|
+
default_executable:
|
39
|
+
dependencies:
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: rake
|
42
|
+
prerelease: false
|
43
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
segments:
|
49
|
+
- 0
|
50
|
+
version: "0"
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id001
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: citrus
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
type: :runtime
|
65
|
+
version_requirements: *id002
|
66
|
+
description: citrus_test makes it easier to test Citrus grammars.
|
67
|
+
email: the.magical.kat@gmail.com
|
68
|
+
executables: []
|
69
|
+
|
70
|
+
extensions: []
|
71
|
+
|
72
|
+
extra_rdoc_files: []
|
73
|
+
|
74
|
+
files:
|
75
|
+
- lib/citrus_test.rb
|
76
|
+
- UNLICENSE
|
77
|
+
- README.md
|
78
|
+
has_rdoc: true
|
79
|
+
homepage: https://github.com/katmagic/citrus_test
|
80
|
+
licenses:
|
81
|
+
- Public Domain
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
segments:
|
93
|
+
- 1
|
94
|
+
- 9
|
95
|
+
- 2
|
96
|
+
version: 1.9.2
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
requirements: []
|
106
|
+
|
107
|
+
rubyforge_project: citrus_test
|
108
|
+
rubygems_version: 1.3.7
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: citrus_test makes it easier to test Citrus grammars.
|
112
|
+
test_files: []
|
113
|
+
|
metadata.gz.sig
ADDED
Binary file
|