Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
yaml-cpp
Commits
c197d822
Commit
c197d822
authored
May 23, 2012
by
Jesse Beder
Browse files
Updated gen emitter tests
parent
277132a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
186 additions
and
19 deletions
+186
-19
test/create-emitter-tests.py
test/create-emitter-tests.py
+10
-3
test/genemittertests.h
test/genemittertests.h
+176
-16
No files found.
test/create-emitter-tests.py
View file @
c197d822
...
@@ -42,7 +42,10 @@ def scalar(value, tag='', anchor='', anchor_id=0):
...
@@ -42,7 +42,10 @@ def scalar(value, tag='', anchor='', anchor_id=0):
if
tag
:
if
tag
:
out_tag
=
encode
(
tag
)
out_tag
=
encode
(
tag
)
else
:
else
:
out_tag
=
'!'
if
value
==
encode
(
value
):
out_tag
=
'?'
else
:
out_tag
=
'!'
emit
+=
[
'"%s"'
%
encode
(
value
)]
emit
+=
[
'"%s"'
%
encode
(
value
)]
return
{
'emit'
:
emit
,
'handle'
:
'SCALAR("%s", %s, "%s")'
%
(
out_tag
,
anchor_id
,
encode
(
value
))}
return
{
'emit'
:
emit
,
'handle'
:
'SCALAR("%s", %s, "%s")'
%
(
out_tag
,
anchor_id
,
encode
(
value
))}
...
@@ -50,7 +53,7 @@ def comment(value):
...
@@ -50,7 +53,7 @@ def comment(value):
return
{
'emit'
:
'YAML::Comment("%s")'
%
value
,
'handle'
:
''
}
return
{
'emit'
:
'YAML::Comment("%s")'
%
value
,
'handle'
:
''
}
def
gen_templates
():
def
gen_templates
():
yield
[[
doc_start
(),
doc_start
(
True
)],
[
scalar
(
'foo
\n
'
)],
[
doc_end
(),
doc_end
(
True
)]]
yield
[[
doc_start
(),
doc_start
(
True
)],
[
scalar
(
'foo'
)],
[
doc_end
(),
doc_end
(
True
)]]
def
expand
(
template
):
def
expand
(
template
):
if
len
(
template
)
==
0
:
if
len
(
template
)
==
0
:
...
@@ -70,7 +73,11 @@ def expand(template):
...
@@ -70,7 +73,11 @@ def expand(template):
def
gen_events
():
def
gen_events
():
for
template
in
gen_templates
():
for
template
in
gen_templates
():
for
events
in
expand
(
template
):
for
events
in
expand
(
template
):
yield
events
base
=
list
(
events
)
for
i
in
range
(
0
,
len
(
base
)
+
1
):
cpy
=
list
(
base
)
cpy
.
insert
(
i
,
comment
(
'comment'
))
yield
cpy
def
gen_tests
():
def
gen_tests
():
for
events
in
gen_events
():
for
events
in
gen_events
():
...
...
test/genemittertests.h
View file @
c197d822
namespace
Emitter
{
namespace
Emitter
{
TEST
test
b3471d40ef2dadee13be
(
YAML
::
Emitter
&
out
)
TEST
test
02571eee35ac0cbd3777
(
YAML
::
Emitter
&
out
)
{
{
out
<<
YAML
::
Comment
(
"comment"
);
out
<<
YAML
::
BeginDoc
;
out
<<
YAML
::
BeginDoc
;
out
<<
"foo
\n
"
;
out
<<
"foo"
;
out
<<
YAML
::
EndDoc
;
out
<<
YAML
::
EndDoc
;
HANDLE
(
out
.
c_str
());
HANDLE
(
out
.
c_str
());
EXPECT_DOC_START
();
EXPECT_DOC_START
();
EXPECT_SCALAR
(
"
!
"
,
0
,
"foo
\n
"
);
EXPECT_SCALAR
(
"
?
"
,
0
,
"foo"
);
EXPECT_DOC_END
();
EXPECT_DOC_END
();
DONE
();
DONE
();
}
}
TEST
test
b1f8cfb6083c3fc130aa
(
YAML
::
Emitter
&
out
)
TEST
test
71b969ca18898d226320
(
YAML
::
Emitter
&
out
)
{
{
out
<<
"foo
\n
"
;
out
<<
YAML
::
BeginDoc
;
out
<<
YAML
::
Comment
(
"comment"
);
out
<<
"foo"
;
out
<<
YAML
::
EndDoc
;
HANDLE
(
out
.
c_str
());
EXPECT_DOC_START
();
EXPECT_SCALAR
(
"?"
,
0
,
"foo"
);
EXPECT_DOC_END
();
DONE
();
}
TEST
testd69e4ea95ce6f221c6e7
(
YAML
::
Emitter
&
out
)
{
out
<<
YAML
::
BeginDoc
;
out
<<
"foo"
;
out
<<
YAML
::
Comment
(
"comment"
);
out
<<
YAML
::
EndDoc
;
HANDLE
(
out
.
c_str
());
EXPECT_DOC_START
();
EXPECT_SCALAR
(
"?"
,
0
,
"foo"
);
EXPECT_DOC_END
();
DONE
();
}
TEST
testffbfd295ad9bef4deb00
(
YAML
::
Emitter
&
out
)
{
out
<<
YAML
::
BeginDoc
;
out
<<
"foo"
;
out
<<
YAML
::
EndDoc
;
out
<<
YAML
::
EndDoc
;
out
<<
YAML
::
Comment
(
"comment"
);
HANDLE
(
out
.
c_str
());
EXPECT_DOC_START
();
EXPECT_SCALAR
(
"?"
,
0
,
"foo"
);
EXPECT_DOC_END
();
DONE
();
}
TEST
test6a459b2fe1f6e961e1a7
(
YAML
::
Emitter
&
out
)
{
out
<<
YAML
::
Comment
(
"comment"
);
out
<<
YAML
::
BeginDoc
;
out
<<
"foo"
;
HANDLE
(
out
.
c_str
());
EXPECT_DOC_START
();
EXPECT_SCALAR
(
"?"
,
0
,
"foo"
);
EXPECT_DOC_END
();
DONE
();
}
TEST
test869ab95640c9933ed4d6
(
YAML
::
Emitter
&
out
)
{
out
<<
YAML
::
BeginDoc
;
out
<<
YAML
::
Comment
(
"comment"
);
out
<<
"foo"
;
HANDLE
(
out
.
c_str
());
EXPECT_DOC_START
();
EXPECT_SCALAR
(
"?"
,
0
,
"foo"
);
EXPECT_DOC_END
();
DONE
();
}
TEST
test433c0771f40ac3ba853e
(
YAML
::
Emitter
&
out
)
{
out
<<
YAML
::
BeginDoc
;
out
<<
"foo"
;
out
<<
YAML
::
Comment
(
"comment"
);
HANDLE
(
out
.
c_str
());
HANDLE
(
out
.
c_str
());
EXPECT_DOC_START
();
EXPECT_DOC_START
();
EXPECT_SCALAR
(
"
!
"
,
0
,
"foo
\n
"
);
EXPECT_SCALAR
(
"
?
"
,
0
,
"foo"
);
EXPECT_DOC_END
();
EXPECT_DOC_END
();
DONE
();
DONE
();
}
}
TEST
test
a2f381bb144cf8886efe
(
YAML
::
Emitter
&
out
)
TEST
test
e181778974c4003bc5a4
(
YAML
::
Emitter
&
out
)
{
{
out
<<
YAML
::
BeginDoc
;
out
<<
YAML
::
BeginDoc
;
out
<<
"foo
\n
"
;
out
<<
"foo"
;
out
<<
YAML
::
Comment
(
"comment"
);
HANDLE
(
out
.
c_str
());
EXPECT_DOC_START
();
EXPECT_SCALAR
(
"?"
,
0
,
"foo"
);
EXPECT_DOC_END
();
DONE
();
}
TEST
test0c7bb03fbd6b52ea3ad6
(
YAML
::
Emitter
&
out
)
{
out
<<
YAML
::
Comment
(
"comment"
);
out
<<
"foo"
;
out
<<
YAML
::
EndDoc
;
HANDLE
(
out
.
c_str
());
EXPECT_DOC_START
();
EXPECT_SCALAR
(
"?"
,
0
,
"foo"
);
EXPECT_DOC_END
();
DONE
();
}
TEST
testb819efb5742c1176df98
(
YAML
::
Emitter
&
out
)
{
out
<<
YAML
::
Comment
(
"comment"
);
out
<<
"foo"
;
out
<<
YAML
::
EndDoc
;
HANDLE
(
out
.
c_str
());
EXPECT_DOC_START
();
EXPECT_SCALAR
(
"?"
,
0
,
"foo"
);
EXPECT_DOC_END
();
DONE
();
}
TEST
test1f7b7cd5a13070c723d3
(
YAML
::
Emitter
&
out
)
{
out
<<
"foo"
;
out
<<
YAML
::
Comment
(
"comment"
);
out
<<
YAML
::
EndDoc
;
HANDLE
(
out
.
c_str
());
EXPECT_DOC_START
();
EXPECT_SCALAR
(
"?"
,
0
,
"foo"
);
EXPECT_DOC_END
();
DONE
();
}
TEST
test32126a88cb2b7311e779
(
YAML
::
Emitter
&
out
)
{
out
<<
"foo"
;
out
<<
YAML
::
EndDoc
;
out
<<
YAML
::
Comment
(
"comment"
);
HANDLE
(
out
.
c_str
());
EXPECT_DOC_START
();
EXPECT_SCALAR
(
"?"
,
0
,
"foo"
);
EXPECT_DOC_END
();
DONE
();
}
TEST
testd7f952713bde5ce2f9e7
(
YAML
::
Emitter
&
out
)
{
out
<<
YAML
::
Comment
(
"comment"
);
out
<<
"foo"
;
HANDLE
(
out
.
c_str
());
EXPECT_DOC_START
();
EXPECT_SCALAR
(
"?"
,
0
,
"foo"
);
EXPECT_DOC_END
();
DONE
();
}
TEST
test5030b4f2d1efb798f320
(
YAML
::
Emitter
&
out
)
{
out
<<
YAML
::
Comment
(
"comment"
);
out
<<
"foo"
;
HANDLE
(
out
.
c_str
());
EXPECT_DOC_START
();
EXPECT_SCALAR
(
"?"
,
0
,
"foo"
);
EXPECT_DOC_END
();
DONE
();
}
TEST
testb9015537b9a9e09b8ec8
(
YAML
::
Emitter
&
out
)
{
out
<<
"foo"
;
out
<<
YAML
::
Comment
(
"comment"
);
HANDLE
(
out
.
c_str
());
HANDLE
(
out
.
c_str
());
EXPECT_DOC_START
();
EXPECT_DOC_START
();
EXPECT_SCALAR
(
"
!
"
,
0
,
"foo
\n
"
);
EXPECT_SCALAR
(
"
?
"
,
0
,
"foo"
);
EXPECT_DOC_END
();
EXPECT_DOC_END
();
DONE
();
DONE
();
}
}
TEST
test
29a80ae92b2f00fa1d06
(
YAML
::
Emitter
&
out
)
TEST
test
03229f6d33fa9007a65d
(
YAML
::
Emitter
&
out
)
{
{
out
<<
"foo
\n
"
;
out
<<
"foo"
;
out
<<
YAML
::
Comment
(
"comment"
);
HANDLE
(
out
.
c_str
());
HANDLE
(
out
.
c_str
());
EXPECT_DOC_START
();
EXPECT_DOC_START
();
EXPECT_SCALAR
(
"
!
"
,
0
,
"foo
\n
"
);
EXPECT_SCALAR
(
"
?
"
,
0
,
"foo"
);
EXPECT_DOC_END
();
EXPECT_DOC_END
();
DONE
();
DONE
();
}
}
}
}
void
RunGenEmitterTests
(
int
&
passed
,
int
&
total
)
void
RunGenEmitterTests
(
int
&
passed
,
int
&
total
)
{
{
RunGenEmitterTest
(
&
Emitter
::
testb3471d40ef2dadee13be
,
"testb3471d40ef2dadee13be"
,
passed
,
total
);
RunGenEmitterTest
(
&
Emitter
::
test02571eee35ac0cbd3777
,
"test02571eee35ac0cbd3777"
,
passed
,
total
);
RunGenEmitterTest
(
&
Emitter
::
testb1f8cfb6083c3fc130aa
,
"testb1f8cfb6083c3fc130aa"
,
passed
,
total
);
RunGenEmitterTest
(
&
Emitter
::
test71b969ca18898d226320
,
"test71b969ca18898d226320"
,
passed
,
total
);
RunGenEmitterTest
(
&
Emitter
::
testa2f381bb144cf8886efe
,
"testa2f381bb144cf8886efe"
,
passed
,
total
);
RunGenEmitterTest
(
&
Emitter
::
testd69e4ea95ce6f221c6e7
,
"testd69e4ea95ce6f221c6e7"
,
passed
,
total
);
RunGenEmitterTest
(
&
Emitter
::
test29a80ae92b2f00fa1d06
,
"test29a80ae92b2f00fa1d06"
,
passed
,
total
);
RunGenEmitterTest
(
&
Emitter
::
testffbfd295ad9bef4deb00
,
"testffbfd295ad9bef4deb00"
,
passed
,
total
);
RunGenEmitterTest
(
&
Emitter
::
test6a459b2fe1f6e961e1a7
,
"test6a459b2fe1f6e961e1a7"
,
passed
,
total
);
RunGenEmitterTest
(
&
Emitter
::
test869ab95640c9933ed4d6
,
"test869ab95640c9933ed4d6"
,
passed
,
total
);
RunGenEmitterTest
(
&
Emitter
::
test433c0771f40ac3ba853e
,
"test433c0771f40ac3ba853e"
,
passed
,
total
);
RunGenEmitterTest
(
&
Emitter
::
teste181778974c4003bc5a4
,
"teste181778974c4003bc5a4"
,
passed
,
total
);
RunGenEmitterTest
(
&
Emitter
::
test0c7bb03fbd6b52ea3ad6
,
"test0c7bb03fbd6b52ea3ad6"
,
passed
,
total
);
RunGenEmitterTest
(
&
Emitter
::
testb819efb5742c1176df98
,
"testb819efb5742c1176df98"
,
passed
,
total
);
RunGenEmitterTest
(
&
Emitter
::
test1f7b7cd5a13070c723d3
,
"test1f7b7cd5a13070c723d3"
,
passed
,
total
);
RunGenEmitterTest
(
&
Emitter
::
test32126a88cb2b7311e779
,
"test32126a88cb2b7311e779"
,
passed
,
total
);
RunGenEmitterTest
(
&
Emitter
::
testd7f952713bde5ce2f9e7
,
"testd7f952713bde5ce2f9e7"
,
passed
,
total
);
RunGenEmitterTest
(
&
Emitter
::
test5030b4f2d1efb798f320
,
"test5030b4f2d1efb798f320"
,
passed
,
total
);
RunGenEmitterTest
(
&
Emitter
::
testb9015537b9a9e09b8ec8
,
"testb9015537b9a9e09b8ec8"
,
passed
,
total
);
RunGenEmitterTest
(
&
Emitter
::
test03229f6d33fa9007a65d
,
"test03229f6d33fa9007a65d"
,
passed
,
total
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment