summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Sidwell <andy@entai.co.uk>2008-06-19 01:49:02 +0000
committerAndrew Sidwell <andy@entai.co.uk>2008-06-19 01:49:02 +0000
commit28b06ed590c8e0d2acb4a0d42e4eca4d6f0aef3c (patch)
tree9f751d125edc733ef13a962348fbeb19af815e4e
parent1db020fb0e52995b2938512496740c11b81d61a3 (diff)
downloadlibhubbub-28b06ed590c8e0d2acb4a0d42e4eca4d6f0aef3c.tar.gz
libhubbub-28b06ed590c8e0d2acb4a0d42e4eca4d6f0aef3c.tar.bz2
Add CDATA tests and the infrastructure to support them.
svn path=/trunk/hubbub/; revision=4410
-rw-r--r--src/tokeniser/tokeniser.c3
-rw-r--r--src/tokeniser/tokeniser.h3
-rw-r--r--test/data/tokeniser2/INDEX1
-rw-r--r--test/data/tokeniser2/cdata.test23
-rw-r--r--test/tokeniser2.c11
-rw-r--r--test/tokeniser3.c11
6 files changed, 52 insertions, 0 deletions
diff --git a/src/tokeniser/tokeniser.c b/src/tokeniser/tokeniser.c
index 1c73e9d..2fe00ac 100644
--- a/src/tokeniser/tokeniser.c
+++ b/src/tokeniser/tokeniser.c
@@ -361,6 +361,9 @@ hubbub_error hubbub_tokeniser_setopt(hubbub_tokeniser *tokeniser,
case HUBBUB_TOKENISER_CONTENT_MODEL:
tokeniser->content_model = params->content_model.model;
break;
+ case HUBBUB_TOKENISER_PROCESS_CDATA:
+ tokeniser->process_cdata_section = params->process_cdata;
+ break;
}
return HUBBUB_OK;
diff --git a/src/tokeniser/tokeniser.h b/src/tokeniser/tokeniser.h
index 20bbe20..2292cd7 100644
--- a/src/tokeniser/tokeniser.h
+++ b/src/tokeniser/tokeniser.h
@@ -27,6 +27,7 @@ typedef enum hubbub_tokeniser_opttype {
HUBBUB_TOKENISER_BUFFER_HANDLER,
HUBBUB_TOKENISER_ERROR_HANDLER,
HUBBUB_TOKENISER_CONTENT_MODEL,
+ HUBBUB_TOKENISER_PROCESS_CDATA
} hubbub_tokeniser_opttype;
/**
@@ -51,6 +52,8 @@ typedef union hubbub_tokeniser_optparams {
struct {
hubbub_content_model model;
} content_model;
+
+ bool process_cdata;
} hubbub_tokeniser_optparams;
/* Create a hubbub tokeniser */
diff --git a/test/data/tokeniser2/INDEX b/test/data/tokeniser2/INDEX
index 00c5e01..8c0bc41 100644
--- a/test/data/tokeniser2/INDEX
+++ b/test/data/tokeniser2/INDEX
@@ -9,3 +9,4 @@ test4.test html5lib tests (part 4)
contentModelFlags.test html5lib content model tests
entities.test html5lib entity tests
escapeFlag.test html5lib escape flag tests
+cdata.test CDATA section tests
diff --git a/test/data/tokeniser2/cdata.test b/test/data/tokeniser2/cdata.test
new file mode 100644
index 0000000..fb4fa8a
--- /dev/null
+++ b/test/data/tokeniser2/cdata.test
@@ -0,0 +1,23 @@
+{"tests": [
+
+{"description":"Basic CDATA test",
+"processCDATA":true,
+"input":"<![CDATA[test]]>",
+"output":[["Character", "test"]]},
+
+{"description":"Unfinished CDATA test",
+"processCDATA":true,
+"input":"<![CDAT",
+"output":["ParseError", ["Comment", "[CDAT"]]},
+
+{"description":"EOF in CDATA chunk",
+"processCDATA":true,
+"input":"<![CDATA[aa",
+"output":[["Character", "aa"]]},
+
+{"description":"False end in CDATA chunk",
+"processCDATA":true,
+"input":"<![CDATA[aa]]aa",
+"output":[["Character", "aa]]aa"]]},
+
+]}
diff --git a/test/tokeniser2.c b/test/tokeniser2.c
index 2ac508c..2054c6b 100644
--- a/test/tokeniser2.c
+++ b/test/tokeniser2.c
@@ -25,6 +25,7 @@ typedef struct context {
const char *last_start_tag;
struct array_list *content_model;
+ bool process_cdata;
} context;
static void run_test(context *ctx);
@@ -97,6 +98,9 @@ int main(int argc, char **argv)
} else if (strcmp(key, "contentModelFlags") == 0) {
ctx.content_model =
json_object_get_array(val);
+ } else if (strcmp(key, "processCDATA") == 0) {
+ ctx.process_cdata =
+ json_object_get_boolean(val);
}
}
@@ -153,6 +157,13 @@ void run_test(context *ctx)
assert(hubbub_tokeniser_run(tok) == HUBBUB_OK);
}
+ if (ctx->process_cdata) {
+ params.process_cdata = ctx->process_cdata;
+ assert(hubbub_tokeniser_setopt(tok,
+ HUBBUB_TOKENISER_PROCESS_CDATA,
+ &params) == HUBBUB_OK);
+ }
+
params.buffer_handler.handler = buffer_handler;
params.buffer_handler.pw = ctx;
assert(hubbub_tokeniser_setopt(tok,
diff --git a/test/tokeniser3.c b/test/tokeniser3.c
index 7b16ba0..523bfcd 100644
--- a/test/tokeniser3.c
+++ b/test/tokeniser3.c
@@ -25,6 +25,7 @@ typedef struct context {
const char *last_start_tag;
struct array_list *content_model;
+ bool process_cdata;
} context;
static void run_test(context *ctx);
@@ -97,6 +98,9 @@ int main(int argc, char **argv)
} else if (strcmp(key, "contentModelFlags") == 0) {
ctx.content_model =
json_object_get_array(val);
+ } else if (strcmp(key, "processCDATA") == 0) {
+ ctx.process_cdata =
+ json_object_get_boolean(val);
}
}
@@ -154,6 +158,13 @@ void run_test(context *ctx)
assert(hubbub_tokeniser_run(tok) == HUBBUB_OK);
}
+ if (ctx->process_cdata) {
+ params.process_cdata = ctx->process_cdata;
+ assert(hubbub_tokeniser_setopt(tok,
+ HUBBUB_TOKENISER_PROCESS_CDATA,
+ &params) == HUBBUB_OK);
+ }
+
params.buffer_handler.handler = buffer_handler;
params.buffer_handler.pw = ctx;
assert(hubbub_tokeniser_setopt(tok,