lxl 0.2.4 → 0.3.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.
- data/CHANGES +13 -0
- data/README.en +68 -0
- data/VERSION +1 -1
- data/lib/lxl.rb +250 -128
- data/setup.rb +1331 -0
- data/test/lxl_test.rb +84 -18
- metadata +4 -3
- data/README +0 -48
data/test/lxl_test.rb
CHANGED
@@ -2,6 +2,12 @@ $LOAD_PATH.unshift('../lib')
|
|
2
2
|
require 'test/unit'
|
3
3
|
require 'lxl'
|
4
4
|
|
5
|
+
class MyNamespace < LXL::Namespace
|
6
|
+
register_symbols :foo
|
7
|
+
register_deferred :bar
|
8
|
+
def capitalize(text) text.to_s.capitalize end
|
9
|
+
end
|
10
|
+
|
5
11
|
class LXLTest < Test::Unit::TestCase
|
6
12
|
|
7
13
|
def test_single_formula
|
@@ -12,33 +18,93 @@ class LXLTest < Test::Unit::TestCase
|
|
12
18
|
formulas = %{
|
13
19
|
This is some text;
|
14
20
|
"This is some ""quoted"" text";
|
15
|
-
="This is some ""quoted"" text"
|
16
|
-
=
|
17
|
-
=
|
18
|
-
=
|
19
|
-
=
|
20
|
-
=
|
21
|
-
=
|
22
|
-
=IN("
|
23
|
-
=
|
24
|
-
=
|
25
|
-
=
|
21
|
+
="This is some ""quoted"" text"
|
22
|
+
=";"=";"
|
23
|
+
=";"=":"
|
24
|
+
=A
|
25
|
+
=B
|
26
|
+
=((1+2)*(10-6))/2
|
27
|
+
=datetime("2004-11-22 11:11:00")=DATE(2004,11,22)+TIME(11,11,00)
|
28
|
+
=IN(" is ", "this is a string")
|
29
|
+
=LIST(1, "two", 3.0)
|
30
|
+
=IN("b", LIST("a", "b", "c"))
|
31
|
+
=AND(TRUE, NULL)
|
32
|
+
=OR(TRUE, FALSE)
|
33
|
+
=IF(1+1=2, "yes", "no")
|
34
|
+
="this" & " and " & "that"
|
35
|
+
=2^3
|
36
|
+
=25%+25.2%
|
37
|
+
=0.25=25%
|
38
|
+
=0.2589=25.89%
|
39
|
+
="embedded percentages 25% and semi-colons ; are working properly"
|
26
40
|
}
|
27
|
-
expected =
|
28
|
-
expected += [:
|
29
|
-
|
30
|
-
|
41
|
+
expected = ["This is some text", "\"This is some \"quoted\" text\"", "This is some \"quoted\" text"]
|
42
|
+
expected += [true, false, :A, :B, 6, true, true, [1, "two", 3.0], true, false, true, "yes", "this and that"]
|
43
|
+
expected += [8, 0.502, true, true, "embedded percentages 25% and semi-colons ; are working properly"]
|
44
|
+
MyNamespace.register_symbols(:A, :B)
|
45
|
+
lxl = LXL::Parser.new(MyNamespace.new)
|
31
46
|
results = lxl.eval(formulas)
|
32
47
|
expected.each_index { |i| assert_equal(expected[i], results[i]) }
|
33
48
|
end
|
49
|
+
|
50
|
+
def test_range
|
51
|
+
lxl = LXL::Parser.new(MyNamespace.new)
|
52
|
+
res = lxl.eval('=LIST(d5:b3, "x")')
|
53
|
+
assert_equal(LXL::Range, res.first.class)
|
54
|
+
assert_equal("B3", res.first.min)
|
55
|
+
assert_equal("D5", res.first.max)
|
56
|
+
assert_equal(res.first.collect.join(','), "B3,B4,B5,C3,C4,C5,D3,D4,D5")
|
57
|
+
end
|
34
58
|
|
35
59
|
def test_deferred
|
36
|
-
|
37
|
-
lxl.
|
60
|
+
MyNamespace.register_deferred(:TESTING)
|
61
|
+
lxl = LXL::Parser.new(MyNamespace.new)
|
38
62
|
res = lxl.eval('=TESTING(1,2,3)')
|
39
63
|
assert_equal(LXL::Deferred, res.class)
|
40
|
-
assert_equal(:
|
64
|
+
assert_equal(:testing, res.symbol)
|
41
65
|
assert_equal(3, res.args.last)
|
42
66
|
end
|
43
67
|
|
68
|
+
def test_ns_methods
|
69
|
+
ns = MyNamespace.new
|
70
|
+
assert_equal(true, ns.and(true, true))
|
71
|
+
assert_equal(false, ns.and(true, false))
|
72
|
+
assert_equal(true, ns.or(true, true))
|
73
|
+
assert_equal(true, ns.or(true, false))
|
74
|
+
assert_equal(false, ns.or(false, false))
|
75
|
+
assert_equal('yes', ns.if(true, 'yes', 'no'))
|
76
|
+
assert_equal('no', ns.if(false, 'yes', 'no'))
|
77
|
+
assert_equal(true, ns.in(1, [1,2]))
|
78
|
+
assert_equal(false, ns.in(1, [3,4]))
|
79
|
+
assert_equal(true, ns.in("a", "ab"))
|
80
|
+
assert_equal(false, ns.in("a", "cd"))
|
81
|
+
assert_equal(true, ns.datetime('Jan 1, 2005') == ns.date(2005,1,1))
|
82
|
+
assert_equal(false, ns.datetime('Jan 1, 2005 12:30') == ns.date(2005,1,1)+ns.time(12,30,01))
|
83
|
+
assert_equal('[1, "two", 3]', ns.list(1,'two',3).inspect)
|
84
|
+
assert_equal('Testing', ns.capitalize('TeSTinG'))
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_ns_symbols
|
88
|
+
ns = MyNamespace.new
|
89
|
+
assert_equal(:FOO, ns.const_get(:FOO))
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_ns_access
|
93
|
+
ns = MyNamespace.new
|
94
|
+
assert_equal(:failed, begin ns.__get__(:class) rescue :failed end)
|
95
|
+
end
|
96
|
+
|
97
|
+
class MyLXLNamespace < LXL::Namespace
|
98
|
+
NAME = 'John Doe'
|
99
|
+
def upper(text) text.to_s.upcase end
|
100
|
+
end
|
101
|
+
|
102
|
+
class MyLXL < LXL::Parser
|
103
|
+
def self.namespace_class() MyLXLNamespace end
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_ns_mylxl
|
107
|
+
assert_equal('JOHN DOE', MyLXL.eval('=UPPER(NAME)'))
|
108
|
+
end
|
109
|
+
|
44
110
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.3
|
|
3
3
|
specification_version: 1
|
4
4
|
name: lxl
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2005-02-
|
6
|
+
version: 0.3.0
|
7
|
+
date: 2005-02-12
|
8
8
|
summary: LXL (Like Excel) is a mini-language that mimics Microsoft Excel formulas. Easily extended with new constants and functions.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -29,9 +29,10 @@ authors:
|
|
29
29
|
files:
|
30
30
|
- lib
|
31
31
|
- VERSION
|
32
|
-
- README
|
33
32
|
- test
|
34
33
|
- CHANGES
|
34
|
+
- setup.rb
|
35
|
+
- README.en
|
35
36
|
- lib/lxl.rb
|
36
37
|
- test/lxl_test.rb
|
37
38
|
test_files: []
|
data/README
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
LXL README
|
2
|
-
============
|
3
|
-
|
4
|
-
LXL (Like Excel) is a mini-language that mimics Microsoft Excel formulas.
|
5
|
-
Easily extended with new constants and functions.
|
6
|
-
|
7
|
-
Usage
|
8
|
-
-----
|
9
|
-
|
10
|
-
formulas = %{
|
11
|
-
This is some text;
|
12
|
-
="This is some ""quoted"" text";
|
13
|
-
=((1+2)*(10-6))/2;
|
14
|
-
=datetime("2004-11-22 11:11:00")=DATE(2004,11,22)+TIME(11,11,00);
|
15
|
-
=IN(" is ", "this is a string");
|
16
|
-
=LIST(1, "two", 3.0);
|
17
|
-
=IN("b", LIST("a", "b", "c"));
|
18
|
-
=AND(TRUE, NULL);
|
19
|
-
=OR(TRUE, FALSE);
|
20
|
-
=IF(1+1=2, "yes", "no");
|
21
|
-
}
|
22
|
-
|
23
|
-
# single formula
|
24
|
-
puts LXL.eval('=5+5').inspect # => 10
|
25
|
-
|
26
|
-
# multiple formulas separated by semi-colon
|
27
|
-
puts LXL.eval(formulas).inspect # => ["This is some text", "This is some \"quoted\" text", 6, true, true, [1, "two", 3.0], true, false, true, "yes"]
|
28
|
-
|
29
|
-
See API docs for more information.
|
30
|
-
|
31
|
-
Requirements
|
32
|
-
------------
|
33
|
-
|
34
|
-
* Ruby 1.8.2
|
35
|
-
|
36
|
-
Install
|
37
|
-
-------
|
38
|
-
|
39
|
-
gem install lxl
|
40
|
-
|
41
|
-
License
|
42
|
-
-------
|
43
|
-
|
44
|
-
LXL incorporates John Carter's LittleLexer for parsing.
|
45
|
-
Distributes under the same terms as LittleLexer.
|
46
|
-
http://www.rubyforge.org/projects/littlelexer/
|
47
|
-
|
48
|
-
Kevin Howe <kh@newclear.ca>
|