2005-12-28 22:44:03 -05:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2005 Jonas Fonseca
|
|
|
|
#
|
|
|
|
|
2005-12-28 23:12:36 -05:00
|
|
|
test_description='Test the very basic parsing of SGML documents.
|
2005-12-28 22:44:03 -05:00
|
|
|
|
|
|
|
This test runs very basic features, like checking that nodes are placed
|
|
|
|
correctly in the DOM tree.
|
|
|
|
'
|
|
|
|
|
|
|
|
. ./libtest
|
|
|
|
|
2005-12-29 00:54:41 -05:00
|
|
|
test_output_equals () {
|
|
|
|
desc="$1"
|
|
|
|
src="$2"
|
|
|
|
out="$3"
|
|
|
|
|
|
|
|
URI="test:$(echo "$desc" | sed '
|
|
|
|
s/^[ \t]*\[[^]]*\][ \t]*//;
|
|
|
|
s/[:., \t][:., \t]*/-/g;
|
|
|
|
s/_/-/g;
|
|
|
|
# *cough*
|
|
|
|
y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/;
|
|
|
|
s/[^a-zA-Z0-9-]//g;')"
|
|
|
|
|
|
|
|
sgml-parser --uri "$URI" --src "$src" | sed 's/^ //' > output
|
|
|
|
echo "#document: $URI" > expected
|
|
|
|
echo "$out" | sed -n '2,$p' >> expected
|
|
|
|
|
|
|
|
test_expect_success "$desc" 'cmp -b output expected'
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-28 22:44:03 -05:00
|
|
|
################################################################
|
2005-12-29 00:54:41 -05:00
|
|
|
# Parse various SGML node types.
|
|
|
|
|
|
|
|
test_output_equals \
|
|
|
|
'Parse a small document.' \
|
|
|
|
'<html><body><p>Hello World!</p></body></html>' \
|
|
|
|
'
|
|
|
|
element: html
|
|
|
|
element: body
|
|
|
|
element: p
|
|
|
|
#text: Hello World!'
|
|
|
|
|
|
|
|
test_output_equals \
|
|
|
|
'Parse an enclosed comment.' \
|
|
|
|
'<root><!-- Hello World! --></root>' \
|
|
|
|
'
|
|
|
|
element: root
|
|
|
|
#comment: Hello World! '
|
|
|
|
|
|
|
|
test_output_equals \
|
|
|
|
'Parse an enclosed CDATA section.' \
|
|
|
|
'<root><![CDATA[...] ]>...]]></root>' \
|
|
|
|
'
|
|
|
|
element: root
|
|
|
|
#cdata-section: ...] ]>...'
|
|
|
|
|
|
|
|
test_output_equals \
|
|
|
|
'Parse attributes.' \
|
|
|
|
'<root lang="fr" attr name="value with &foo; <stuff"></root>' \
|
|
|
|
'
|
|
|
|
element: root
|
|
|
|
attribute: lang -> fr
|
|
|
|
attribute: attr ->
|
|
|
|
attribute: name -> value with &foo; <stuff'
|
|
|
|
|
|
|
|
test_output_equals \
|
|
|
|
'Parse entity references.' \
|
|
|
|
'<root>&...*...&...copy;...&;...&#;' \
|
|
|
|
'
|
|
|
|
element: root
|
|
|
|
entity-reference: amp
|
|
|
|
#text: ...
|
|
|
|
entity-reference: #42
|
|
|
|
#text: ...
|
|
|
|
entity-reference: ...copy
|
|
|
|
#text: ...
|
|
|
|
#text: &;
|
|
|
|
#text: ...
|
|
|
|
entity-reference: #'
|
|
|
|
|
|
|
|
# Test <?>
|
|
|
|
test_output_equals \
|
|
|
|
'Parse processing instructions.' \
|
|
|
|
'<?xml encoding="UTF8"?>
|
|
|
|
...
|
|
|
|
<?ecmascript
|
|
|
|
var val=2;
|
|
|
|
?>' \
|
|
|
|
'
|
|
|
|
proc-instruction: xml -> encoding="UTF8"
|
|
|
|
attribute: encoding -> UTF8
|
|
|
|
#text: \n...\n
|
|
|
|
proc-instruction: ecmascript -> \nvar -> val=2;\n'
|
2005-12-28 22:44:03 -05:00
|
|
|
|
|
|
|
test_done
|