kwaff 1.0.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/COPYING +340 -0
- data/ChangeLog.txt +118 -0
- data/README.txt +96 -0
- data/bin/kwaff +131 -0
- data/doc/docstyle.css +307 -0
- data/doc/examples.html +1283 -0
- data/doc/users-guide.html +395 -0
- data/examples/Makefile +17 -0
- data/examples/ant/Makefile +7 -0
- data/examples/ant/build.kwaff +57 -0
- data/examples/hibernate/AuctionItem.hbm.kwaff +45 -0
- data/examples/hibernate/Bid.hbm.kwaff +42 -0
- data/examples/hibernate/Makefile +9 -0
- data/examples/hibernate/User.hbm.kwaff +65 -0
- data/examples/hibernate/hibernate.cfg.kwaff +17 -0
- data/examples/seasar2/Makefile +9 -0
- data/examples/seasar2/seasar2.kwaff +62 -0
- data/examples/servlet/Makefile +9 -0
- data/examples/servlet/web.kwaff +37 -0
- data/examples/spring/Makefile +9 -0
- data/examples/spring/applicationContext.kwaff +147 -0
- data/examples/xhtml/Makefile +9 -0
- data/examples/xhtml/README.kwaff +84 -0
- data/examples/xi/Makefile +9 -0
- data/examples/xi/bbs.kwaff +58 -0
- data/lib/kwaff.rb +85 -0
- data/lib/kwaff/doctype.rb +124 -0
- data/lib/kwaff/doctypes.yaml +138 -0
- data/lib/kwaff/errors.rb +26 -0
- data/lib/kwaff/node.rb +101 -0
- data/lib/kwaff/optparse.rb +101 -0
- data/lib/kwaff/orderedhash.rb +56 -0
- data/lib/kwaff/parser.rb +342 -0
- data/lib/kwaff/rexml.rb +394 -0
- data/lib/kwaff/translator.rb +275 -0
- data/setup.rb +1331 -0
- data/test/ex101.exp +10 -0
- data/test/ex101.in +8 -0
- data/test/ex102.exp +14 -0
- data/test/ex102.in +16 -0
- data/test/ex103.exp +13 -0
- data/test/ex103.in +13 -0
- data/test/ex104.exp +24 -0
- data/test/ex104.in +24 -0
- data/test/ex105.exp +12 -0
- data/test/ex105.in +18 -0
- data/test/ex106.exp +22 -0
- data/test/ex106.in +21 -0
- data/test/ex107.exp +14 -0
- data/test/ex107.in +14 -0
- data/test/ex111.exp +7 -0
- data/test/ex111.in +13 -0
- data/test/ex112.exp +15 -0
- data/test/ex112.in +16 -0
- data/test/ex113.exp +23 -0
- data/test/ex113.in +22 -0
- data/test/ex114.exp +12 -0
- data/test/ex114.in +17 -0
- data/test/ex115.exp +9 -0
- data/test/ex115.in +12 -0
- data/test/ex121.exp +10 -0
- data/test/ex121.in +8 -0
- data/test/ex122.exp +10 -0
- data/test/ex122.in +8 -0
- data/test/ex301.exp +13 -0
- data/test/ex301.in +14 -0
- data/test/ex302.exp +15 -0
- data/test/ex302.in +18 -0
- data/test/ex303.exp +15 -0
- data/test/ex303.in +16 -0
- data/test/ex304.exp +17 -0
- data/test/ex304.in +15 -0
- data/test/ex311.exp +18 -0
- data/test/ex311.in +32 -0
- data/test/ex312.exp +21 -0
- data/test/ex312.in +18 -0
- data/test/ex313.exp +20 -0
- data/test/ex313.in +33 -0
- data/test/ex314.exp +34 -0
- data/test/ex314.in +24 -0
- data/test/ex801.exp +16 -0
- data/test/ex801.in +15 -0
- data/test/test.rb +273 -0
- data/todo.txt +1 -0
- metadata +132 -0
data/test/ex301.exp
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
<beans>
|
2
|
+
<bean destroy-method='close' class='org.apache.commons.dhcp.BasicDataScope' id='myDataSource'>
|
3
|
+
<property name='driverClassName'>
|
4
|
+
<value>com.mysql.jdbc.Driver</value>
|
5
|
+
</property>
|
6
|
+
<property name='url'>
|
7
|
+
<value>jdbc:mysql://localhost:3306/mydb</value>
|
8
|
+
</property>
|
9
|
+
<property name='username'>
|
10
|
+
<value>root</value>
|
11
|
+
</property>
|
12
|
+
</bean>
|
13
|
+
</beans>
|
data/test/ex301.in
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
* beans
|
2
|
+
* bean
|
3
|
+
- id=myDataSource
|
4
|
+
- class=org.apache.commons.dhcp.BasicDataScope
|
5
|
+
- destroy-method=close
|
6
|
+
* property
|
7
|
+
- name=driverClassName
|
8
|
+
* value=com.mysql.jdbc.Driver
|
9
|
+
* property
|
10
|
+
- name=url
|
11
|
+
* value=jdbc:mysql://localhost:3306/mydb
|
12
|
+
* property
|
13
|
+
- name=username
|
14
|
+
* value=root
|
data/test/ex302.exp
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
|
3
|
+
<beans>
|
4
|
+
<bean class="org.apache.commons.dhcp.BasicDataScope" destroy-method="close" id="myDataSource">
|
5
|
+
<property name="driverClassName">
|
6
|
+
<value>com.mysql.jdbc.Driver</value>
|
7
|
+
</property>
|
8
|
+
<property name="url">
|
9
|
+
<value>jdbc:mysql://localhost:3306/mydb</value>
|
10
|
+
</property>
|
11
|
+
<property name="username">
|
12
|
+
<value>root</value>
|
13
|
+
</property>
|
14
|
+
</bean>
|
15
|
+
</beans>
|
data/test/ex302.in
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
|
3
|
+
"http://www.springframework.org/dtd/spring-beans.dtd">
|
4
|
+
<beans>
|
5
|
+
<bean id="myDataSource"
|
6
|
+
class="org.apache.commons.dhcp.BasicDataScope"
|
7
|
+
destroy-method="close">
|
8
|
+
<property name="driverClassName">
|
9
|
+
<value>com.mysql.jdbc.Driver</value>
|
10
|
+
</property>
|
11
|
+
<property name="url">
|
12
|
+
<value>jdbc:mysql://localhost:3306/mydb</value>
|
13
|
+
</property>
|
14
|
+
<property name="username">
|
15
|
+
<value>root</value>
|
16
|
+
</property>
|
17
|
+
</bean>
|
18
|
+
</beans>
|
data/test/ex303.exp
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
<?xml version='1.0'?>
|
2
|
+
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
|
3
|
+
<beans>
|
4
|
+
<bean destroy-method='close' class='org.apache.commons.dhcp.BasicDataScope' id='myDataSource'>
|
5
|
+
<property name='driverClassName'>
|
6
|
+
<value>com.mysql.jdbc.Driver</value>
|
7
|
+
</property>
|
8
|
+
<property name='url'>
|
9
|
+
<value>jdbc:mysql://localhost:3306/mydb</value>
|
10
|
+
</property>
|
11
|
+
<property name='username'>
|
12
|
+
<value>root</value>
|
13
|
+
</property>
|
14
|
+
</bean>
|
15
|
+
</beans>
|
data/test/ex303.in
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
// @desc: rexml tree -> kwaff string
|
2
|
+
?doctype = @spring-beans
|
3
|
+
* beans
|
4
|
+
* bean
|
5
|
+
- id=myDataSource
|
6
|
+
- class=org.apache.commons.dhcp.BasicDataScope
|
7
|
+
- destroy-method=close
|
8
|
+
* property
|
9
|
+
- name=driverClassName
|
10
|
+
* value=com.mysql.jdbc.Driver
|
11
|
+
* property
|
12
|
+
- name=url
|
13
|
+
* value=jdbc:mysql://localhost:3306/mydb
|
14
|
+
* property
|
15
|
+
- name=username
|
16
|
+
* value=root
|
data/test/ex304.exp
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
?xmlversion = 1.0
|
2
|
+
?encoding = UTF-8
|
3
|
+
?doctype = @spring-beans
|
4
|
+
* beans
|
5
|
+
* bean
|
6
|
+
- class = org.apache.commons.dhcp.BasicDataScope
|
7
|
+
- destroy-method = close
|
8
|
+
- id = myDataSource
|
9
|
+
* property
|
10
|
+
- name = driverClassName
|
11
|
+
* value = com.mysql.jdbc.Driver
|
12
|
+
* property
|
13
|
+
- name = url
|
14
|
+
* value = jdbc:mysql://localhost:3306/mydb
|
15
|
+
* property
|
16
|
+
- name = username
|
17
|
+
* value = root
|
data/test/ex304.in
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
|
3
|
+
<beans>
|
4
|
+
<bean class="org.apache.commons.dhcp.BasicDataScope" destroy-method="close" id="myDataSource">
|
5
|
+
<property name="driverClassName">
|
6
|
+
<value>com.mysql.jdbc.Driver</value>
|
7
|
+
</property>
|
8
|
+
<property name="url">
|
9
|
+
<value>jdbc:mysql://localhost:3306/mydb</value>
|
10
|
+
</property>
|
11
|
+
<property name="username">
|
12
|
+
<value>root</value>
|
13
|
+
</property>
|
14
|
+
</bean>
|
15
|
+
</beans>
|
data/test/ex311.exp
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
<html>
|
2
|
+
<!--html headers-->
|
3
|
+
<head>
|
4
|
+
<title>Kwaff Example</title>
|
5
|
+
<meta content='text/html; charset=ISO-8859-1' http-equiv='Content-Type'/>
|
6
|
+
<stylesheet href='/stylesheet.css' type='text/css'/>
|
7
|
+
</head>
|
8
|
+
<!--main body-->
|
9
|
+
<body>
|
10
|
+
<div class='breadcrumbs'>
|
11
|
+
<a href='/'>Home</a>><a href='/ruby/'>Ruby</a>><a href='/ruby/kwaff/'>Kwaff</a>
|
12
|
+
</div>
|
13
|
+
<h1>Kwaff Example</h1>
|
14
|
+
<p>This is an example of Kwaff.</p>
|
15
|
+
<!--special chars: < > & " '-->
|
16
|
+
<p style='special chars: < > & " ''>special chars: < > & " '</p>
|
17
|
+
</body>
|
18
|
+
</html>
|
data/test/ex311.in
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
? doctype = @xhtml
|
2
|
+
* html
|
3
|
+
# html headers
|
4
|
+
* head
|
5
|
+
* title = Kwaff Example
|
6
|
+
* meta
|
7
|
+
- http-equiv = Content-Type
|
8
|
+
- content = text/html; charset=ISO-8859-1
|
9
|
+
* stylesheet
|
10
|
+
- href = /stylesheet.css
|
11
|
+
- type = text/css
|
12
|
+
# main body
|
13
|
+
* body
|
14
|
+
* div
|
15
|
+
- class = breadcrumbs
|
16
|
+
* a = Home
|
17
|
+
- href = /
|
18
|
+
. >
|
19
|
+
* a = Ruby
|
20
|
+
- href = /ruby/
|
21
|
+
. >
|
22
|
+
* a = Kwaff
|
23
|
+
- href = /ruby/kwaff/
|
24
|
+
* h1 = Kwaff Example
|
25
|
+
* p = <<END
|
26
|
+
This is an example of Kwaff.
|
27
|
+
END
|
28
|
+
# special chars: < > & " '
|
29
|
+
* p
|
30
|
+
- style = special chars: < > & " '
|
31
|
+
. special chars: < > & " '
|
32
|
+
|
data/test/ex312.exp
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<html>
|
3
|
+
<!-- html headers -->
|
4
|
+
<head>
|
5
|
+
<title>Kwaff Example</title>
|
6
|
+
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"/>
|
7
|
+
<stylesheet href="/stylesheet.css" type="text/css"/>
|
8
|
+
</head>
|
9
|
+
<!-- main body -->
|
10
|
+
<body>
|
11
|
+
<div class="breadcrumbs">
|
12
|
+
<a href="/">Home</a>
|
13
|
+
><a href="/ruby/">Ruby</a>
|
14
|
+
><a href="/ruby/kwaff/">Kwaff</a>
|
15
|
+
</div>
|
16
|
+
<h1>Kwaff Example</h1>
|
17
|
+
<p>This is an example of Kwaff.</p>
|
18
|
+
<!-- special chars: < > & " ' -->
|
19
|
+
<p style="special chars: < > & " '">special chars: < > & " '</p>
|
20
|
+
</body>
|
21
|
+
</html>
|
data/test/ex312.in
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
<html>
|
2
|
+
<!--html headers-->
|
3
|
+
<head>
|
4
|
+
<title>Kwaff Example</title>
|
5
|
+
<meta content='text/html; charset=ISO-8859-1' http-equiv='Content-Type'/>
|
6
|
+
<stylesheet href='/stylesheet.css' type='text/css'/>
|
7
|
+
</head>
|
8
|
+
<!--main body-->
|
9
|
+
<body>
|
10
|
+
<div class='breadcrumbs'>
|
11
|
+
<a href='/'>Home</a>><a href='/ruby/'>Ruby</a>><a href='/ruby/kwaff/'>Kwaff</a>
|
12
|
+
</div>
|
13
|
+
<h1>Kwaff Example</h1>
|
14
|
+
<p>This is an example of Kwaff.</p>
|
15
|
+
<!--special chars: < > & " '-->
|
16
|
+
<p style='special chars: < > & " ''>special chars: < > & " '</p>
|
17
|
+
</body>
|
18
|
+
</html>
|
data/test/ex313.exp
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
<?xml version='1.0'?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html>
|
4
|
+
<!--html headers-->
|
5
|
+
<head>
|
6
|
+
<title>Kwaff Example</title>
|
7
|
+
<meta content='text/html; charset=ISO-8859-1' http-equiv='Content-Type'/>
|
8
|
+
<stylesheet href='/stylesheet.css' type='text/css'/>
|
9
|
+
</head>
|
10
|
+
<!--main body-->
|
11
|
+
<body>
|
12
|
+
<div class='breadcrumbs'>
|
13
|
+
<a href='/'>Home</a>><a href='/ruby/'>Ruby</a>><a href='/ruby/kwaff/'>Kwaff</a>
|
14
|
+
</div>
|
15
|
+
<h1>Kwaff Example</h1>
|
16
|
+
<p>This is an example of Kwaff.</p>
|
17
|
+
<!--special chars: < > & " '-->
|
18
|
+
<p style='special chars: < > & " ''>special chars: < > & " '</p>
|
19
|
+
</body>
|
20
|
+
</html>
|
data/test/ex313.in
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
// @desc: Kwaff::Rexml::Parser == kwaff string -> rexml tree
|
2
|
+
? doctype = @xhtml
|
3
|
+
* html
|
4
|
+
# html headers
|
5
|
+
* head
|
6
|
+
* title = Kwaff Example
|
7
|
+
* meta
|
8
|
+
- http-equiv = Content-Type
|
9
|
+
- content = text/html; charset=ISO-8859-1
|
10
|
+
* stylesheet
|
11
|
+
- href = /stylesheet.css
|
12
|
+
- type = text/css
|
13
|
+
# main body
|
14
|
+
* body
|
15
|
+
* div
|
16
|
+
- class = breadcrumbs
|
17
|
+
* a = Home
|
18
|
+
- href = /
|
19
|
+
. >
|
20
|
+
* a = Ruby
|
21
|
+
- href = /ruby/
|
22
|
+
. >
|
23
|
+
* a = Kwaff
|
24
|
+
- href = /ruby/kwaff/
|
25
|
+
* h1 = Kwaff Example
|
26
|
+
* p = <<END
|
27
|
+
This is an example of Kwaff.
|
28
|
+
END
|
29
|
+
# special chars: < > & " '
|
30
|
+
* p
|
31
|
+
- style = special chars: < > & " '
|
32
|
+
. special chars: < > & " '
|
33
|
+
|
data/test/ex314.exp
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
?xmlversion = 1.0
|
2
|
+
?encoding = UTF-8
|
3
|
+
?doctype = @xhtml10-transitional
|
4
|
+
* html
|
5
|
+
# html headers
|
6
|
+
* head
|
7
|
+
* title = Kwaff Example
|
8
|
+
* meta
|
9
|
+
- content = text/html; charset=ISO-8859-1
|
10
|
+
- http-equiv = Content-Type
|
11
|
+
* stylesheet
|
12
|
+
- href = /stylesheet.css
|
13
|
+
- type = text/css
|
14
|
+
# main body
|
15
|
+
* body
|
16
|
+
* div
|
17
|
+
- class = breadcrumbs
|
18
|
+
* a = Home
|
19
|
+
- href = /
|
20
|
+
. >
|
21
|
+
* a = Ruby
|
22
|
+
- href = /ruby/
|
23
|
+
. >
|
24
|
+
* a = Kwaff
|
25
|
+
- href = /ruby/kwaff/
|
26
|
+
* h1 = Kwaff Example
|
27
|
+
* p
|
28
|
+
.
|
29
|
+
. This is an example of Kwaff.
|
30
|
+
. Kwaff is more friendly format than XML.
|
31
|
+
.
|
32
|
+
# special chars: < > & " '
|
33
|
+
* p = special chars: < > & " '
|
34
|
+
- style = special chars: < > & " '
|
data/test/ex314.in
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
4
|
+
<html>
|
5
|
+
<!-- html headers -->
|
6
|
+
<head>
|
7
|
+
<title>Kwaff Example</title>
|
8
|
+
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"/>
|
9
|
+
<stylesheet href="/stylesheet.css" type="text/css"/>
|
10
|
+
</head>
|
11
|
+
<!-- main body -->
|
12
|
+
<body>
|
13
|
+
<div class="breadcrumbs">
|
14
|
+
<a href="/">Home</a>><a href="/ruby/">Ruby</a>><a href="/ruby/kwaff/">Kwaff</a>
|
15
|
+
</div>
|
16
|
+
<h1>Kwaff Example</h1>
|
17
|
+
<p>
|
18
|
+
This is an example of Kwaff.
|
19
|
+
Kwaff is more friendly format than XML.
|
20
|
+
</p>
|
21
|
+
<!-- special chars: < > & " ' -->
|
22
|
+
<p style="special chars: < > & " '">special chars: < > & " '</p>
|
23
|
+
</body>
|
24
|
+
</html>
|
data/test/ex801.exp
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
|
3
|
+
"http://www.springframework.org/dtd/spring-beans.dtd">
|
4
|
+
<beans>
|
5
|
+
<bean id="myDataSource" class="org.apache.commons.dhcp.BasicDataScope" destroy-method="close">
|
6
|
+
<property name="driverClassName">
|
7
|
+
<value>com.mysql.jdbc.Driver</value>
|
8
|
+
</property>
|
9
|
+
<property name="url">
|
10
|
+
<value>jdbc:mysql://localhost:3306/mydb</value>
|
11
|
+
</property>
|
12
|
+
<property name="username">
|
13
|
+
<value>root</value>
|
14
|
+
</property>
|
15
|
+
</bean>
|
16
|
+
</beans>
|
data/test/ex801.in
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
?doctype = @spring-beans
|
2
|
+
* beans
|
3
|
+
* bean
|
4
|
+
- id = myDataSource
|
5
|
+
- class = org.apache.commons.dhcp.BasicDataScope
|
6
|
+
- destroy-method = close
|
7
|
+
* property
|
8
|
+
- name = driverClassName
|
9
|
+
* value = com.mysql.jdbc.Driver
|
10
|
+
* property
|
11
|
+
- name = url
|
12
|
+
* value = jdbc:mysql://localhost:3306/mydb
|
13
|
+
* property
|
14
|
+
- name = username
|
15
|
+
* value = root
|
data/test/test.rb
ADDED
@@ -0,0 +1,273 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
###
|
4
|
+
### test script for kwaff.rb
|
5
|
+
###
|
6
|
+
### $Id: test.rb 14 2005-06-10 09:01:18Z kwatch $
|
7
|
+
### $Release: 1.0.0 $
|
8
|
+
### copyright(c) 2005 kuwata-lab.com all rights reserved
|
9
|
+
###
|
10
|
+
|
11
|
+
BASE_DIR = File::dirname($0)
|
12
|
+
$: << "#{BASE_DIR}/../lib"
|
13
|
+
|
14
|
+
require 'test/unit'
|
15
|
+
require 'test/unit/ui/console/testrunner'
|
16
|
+
require 'rexml/document'
|
17
|
+
require 'stringio'
|
18
|
+
require 'kwaff'
|
19
|
+
require 'kwaff/rexml'
|
20
|
+
|
21
|
+
|
22
|
+
require 'test/unit'
|
23
|
+
require 'tempfile'
|
24
|
+
|
25
|
+
module Test
|
26
|
+
module Unit
|
27
|
+
class TestCase
|
28
|
+
def assert_equal_with_diff(expected, actual, diffopt='-u', flag_cut=true)
|
29
|
+
if expected == actual
|
30
|
+
assert(true)
|
31
|
+
return
|
32
|
+
end
|
33
|
+
|
34
|
+
if expected[-1] != ?\n || actual[-1] != ?\n
|
35
|
+
expected += "\n"
|
36
|
+
actual += "\n"
|
37
|
+
end
|
38
|
+
expfile = Tempfile.new(".expected.")
|
39
|
+
expfile.write(expected); expfile.flush()
|
40
|
+
actfile = Tempfile.new(".actual.")
|
41
|
+
actfile.write(actual); actfile.flush()
|
42
|
+
diff = `diff #{diffopt} #{expfile.path} #{actfile.path}`
|
43
|
+
expfile.close(true)
|
44
|
+
actfile.close(true)
|
45
|
+
|
46
|
+
# cut 1st & 2nd lines
|
47
|
+
message = flag_cut ? diff.gsub(/\A.*\n.*\n/, '') : diff
|
48
|
+
#raise Test::Unit::AssertionFailedError.new(message)
|
49
|
+
assert_block(message) { false } # or assert(false, message)
|
50
|
+
end
|
51
|
+
def assert_equal(expected, actual)
|
52
|
+
return assert_equal_with_diff(expected, actual)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
class KwaffBasicTest < Test::Unit::TestCase
|
60
|
+
def _test(input, expected, flag_quiet=false)
|
61
|
+
document = Kwaff.parse_document(input)
|
62
|
+
output = document.to_xml()
|
63
|
+
assert_equal(expected, output)
|
64
|
+
end
|
65
|
+
|
66
|
+
def _test_convert(number) ## kwaff -> xml
|
67
|
+
basename = "#{BASE_DIR}/ex#{number}"
|
68
|
+
input = File.open("#{basename}.in") { |f| f.read }
|
69
|
+
expected = File.open("#{basename}.exp") { |f| f.read }
|
70
|
+
document = Kwaff.parse_document(input)
|
71
|
+
output = document.to_xml()
|
72
|
+
File.open("#{basename}.out", "w") { |f| f.write(output) }
|
73
|
+
assert_equal(expected, output)
|
74
|
+
end
|
75
|
+
|
76
|
+
numlist = []
|
77
|
+
numlist.concat( (101..107).to_a )
|
78
|
+
numlist.concat( (111..115).to_a )
|
79
|
+
s = ''
|
80
|
+
numlist.each do |num|
|
81
|
+
s << <<-END
|
82
|
+
def test_conver#{num}
|
83
|
+
_test_convert(#{num})
|
84
|
+
end
|
85
|
+
END
|
86
|
+
end
|
87
|
+
eval s
|
88
|
+
|
89
|
+
|
90
|
+
def _test_indent(number, indent_width=nil, output_indent_width=nil)
|
91
|
+
basename = "#{BASE_DIR}/ex#{number}"
|
92
|
+
input = File.open("#{basename}.in") { |f| f.read }
|
93
|
+
expected = File.open("#{basename}.exp") { |f| f.read }
|
94
|
+
toppings = {}
|
95
|
+
toppings[:indent_width] = indent_width if indent_width
|
96
|
+
toppings[:output_indent_width] = output_indent_width if output_indent_width
|
97
|
+
document = Kwaff.parse_document(input, toppings)
|
98
|
+
translator = Kwaff::XmlTranslator.new(toppings)
|
99
|
+
output = translator.translate(document)
|
100
|
+
File.open("#{basename}.out", "w") { |f| f.write(output) }
|
101
|
+
assert_equal(expected, output)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_indent121 # indent_width
|
105
|
+
_test_indent(121, 3, nil)
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_indent122 # output_indent_width
|
109
|
+
_test_indent(122, nil, 1)
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
def _test_err(input)
|
115
|
+
document = Kwaff.parse_document(input)
|
116
|
+
output = document.to_xml()
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
def test_err201 ## invalid indent
|
121
|
+
input = <<END
|
122
|
+
* foo
|
123
|
+
* bar
|
124
|
+
END
|
125
|
+
assert_raise(Kwaff::ParseError) do
|
126
|
+
_test_err(input)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
def test_err202 ## invalid indent of attr
|
132
|
+
input = <<END
|
133
|
+
* foo
|
134
|
+
- attr1 = val1
|
135
|
+
- attr2 = val2
|
136
|
+
END
|
137
|
+
assert_raise(Kwaff::ParseError) do
|
138
|
+
_test_err(input)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
def test_err203 ## invalid attr format
|
144
|
+
input = <<END
|
145
|
+
* foo
|
146
|
+
- attr1
|
147
|
+
END
|
148
|
+
assert_raise(Kwaff::ParseError) do
|
149
|
+
_test_err(input)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
end # KwaffBasicTest
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
class KwaffRexmlTest < Test::Unit::TestCase
|
158
|
+
|
159
|
+
def _readfile(number, suffix)
|
160
|
+
basename = "#{BASE_DIR}/ex#{number}"
|
161
|
+
filename = "#{basename}#{suffix}"
|
162
|
+
str = File.open(filename) { |f| f.read }
|
163
|
+
return str
|
164
|
+
end
|
165
|
+
|
166
|
+
def _writefile(output, number, suffix=".out")
|
167
|
+
basename = "#{BASE_DIR}/ex#{number}"
|
168
|
+
filename = "#{basename}#{suffix}"
|
169
|
+
File.open(filename, "w") { |f| f.write(output) }
|
170
|
+
end
|
171
|
+
|
172
|
+
## kwaff str => kwaff tree => rexml tree => xml str
|
173
|
+
def _test_rexml1(num) ## convert to REXML document
|
174
|
+
input = _readfile(num, ".in")
|
175
|
+
expected = _readfile(num, ".exp")
|
176
|
+
#expected.chop!
|
177
|
+
parser = Kwaff::Parser.new(input)
|
178
|
+
document = parser.parse_document()
|
179
|
+
#
|
180
|
+
translator = Kwaff::RexmlTranslator.new
|
181
|
+
rexml_document = translator.translate(document)
|
182
|
+
sio = StringIO.new() ; rexml_document.root.write(sio, 0) ; output = sio.string
|
183
|
+
output.gsub!(/\n[ \t]*-->/m, '-->')
|
184
|
+
_writefile(output, num)
|
185
|
+
assert_equal(expected, output)
|
186
|
+
#
|
187
|
+
rexml_document = document.to_rexml() ## <=
|
188
|
+
sio = StringIO.new() ; rexml_document.root.write(sio, 0) ; output = sio.string
|
189
|
+
output.gsub!(/\n[ \t]*-->/m, '-->')
|
190
|
+
_writefile(output, num)
|
191
|
+
assert_equal(expected, output)
|
192
|
+
end
|
193
|
+
def test_rexml301
|
194
|
+
_test_rexml1(301)
|
195
|
+
end
|
196
|
+
def test_rexml311
|
197
|
+
_test_rexml1(311)
|
198
|
+
end
|
199
|
+
|
200
|
+
|
201
|
+
## xml str => rexml tree => kwaff tree => xml str
|
202
|
+
def _test_rexml2(num) ## REXML node => Kwaff node
|
203
|
+
input = _readfile(num, ".in")
|
204
|
+
expected = _readfile(num, ".exp")
|
205
|
+
rexml_document = REXML::Document.new(input)
|
206
|
+
translator = Kwaff::Rexml::ReverseTranslator.new()
|
207
|
+
document = translator.translate(rexml_document)
|
208
|
+
output = document.to_xml
|
209
|
+
_writefile(output, num)
|
210
|
+
assert_equal(expected, output)
|
211
|
+
end
|
212
|
+
def test_rexml302
|
213
|
+
_test_rexml2(302)
|
214
|
+
end
|
215
|
+
def test_rexml312
|
216
|
+
_test_rexml2(312)
|
217
|
+
end
|
218
|
+
|
219
|
+
|
220
|
+
## Kwaff::Rexml::Parser = kwaff str -> rexml tree
|
221
|
+
def _test_rexml3(num) ## Kwaff::Rexml::Parser and Kwaff::Rexml::parse_document()
|
222
|
+
input = _readfile(num, ".in")
|
223
|
+
expected = _readfile(num, ".exp")
|
224
|
+
#expected.chop!
|
225
|
+
parser = Kwaff::Rexml::Parser.new(input)
|
226
|
+
rexml_document = parser.parse_document()
|
227
|
+
sio = StringIO.new ; rexml_document.write(sio, 0) ; output = sio.string
|
228
|
+
output.gsub!(/\n[ \t]*-->/m, '-->')
|
229
|
+
_writefile(output, num)
|
230
|
+
assert_equal(expected, output)
|
231
|
+
rexml_document = Kwaff::Rexml::parse_document(input)
|
232
|
+
sio = StringIO.new ; rexml_document.write(sio, 0) ; output = sio.string
|
233
|
+
output.gsub!(/\n[ \t]*-->/m, '-->')
|
234
|
+
_writefile(output, num)
|
235
|
+
assert_equal(expected, output)
|
236
|
+
end
|
237
|
+
def test_rexml303
|
238
|
+
_test_rexml3(303)
|
239
|
+
end
|
240
|
+
def test_rexml313
|
241
|
+
_test_rexml3(313)
|
242
|
+
end
|
243
|
+
|
244
|
+
|
245
|
+
## Kwaff::Rexml::KwaffTranslator == rexml tree -> kwaff string
|
246
|
+
def _test_rexml4(num) ## Kwaff::Rexml::KwaffTranslator and Kwaff::Rexml::revert()
|
247
|
+
input = _readfile(num, ".in")
|
248
|
+
expected = _readfile(num, ".exp")
|
249
|
+
rexml_document = REXML::Document.new(input)
|
250
|
+
translator = Kwaff::Rexml::KwaffTranslator.new()
|
251
|
+
output = translator.translate(rexml_document)
|
252
|
+
output.gsub!(/\n[ \t]*-->/m, '-->')
|
253
|
+
_writefile(output, num)
|
254
|
+
assert_equal(expected, output)
|
255
|
+
output = Kwaff::Rexml::revert(input)
|
256
|
+
output.gsub!(/\n[ \t]*-->/m, '-->')
|
257
|
+
_writefile(output, num)
|
258
|
+
assert_equal(expected, output)
|
259
|
+
end
|
260
|
+
def test_rexml304
|
261
|
+
_test_rexml4(304)
|
262
|
+
end
|
263
|
+
def test_rexml314
|
264
|
+
_test_rexml4(314)
|
265
|
+
end
|
266
|
+
|
267
|
+
end
|
268
|
+
|
269
|
+
|
270
|
+
suite = Test::Unit::TestSuite.new()
|
271
|
+
suite << KwaffBasicTest.suite()
|
272
|
+
suite << KwaffRexmlTest.suite()
|
273
|
+
Test::Unit::UI::Console::TestRunner.run(suite)
|