grim/gplate
Clone
Summary
Browse
Changes
Graph
rewording so vim syntax highlighting doesn't blow up
2009-06-21, Gary Kramlich
4e8d21e4d53d
rewording so vim syntax highlighting doesn't blow up
#ifdef HAVE_CONFIG_H
#
include
<config.h>
#endif
/* HAVE_CONFIG_H */
#include
<check.h>
#include
<stdio.h>
#include
<string.h>
#include
<gplate/gplate.h>
#include
"test.h"
/******************************************************************************
* Structs
*****************************************************************************/
typedef
struct
{
const
gchar
*
name
;
const
gchar
*
value
;
}
ForData
;
/******************************************************************************
* Globals
*****************************************************************************/
static
GPlateTemplate
*
tplate
=
NULL
;
static
GPlateVariable
*
dict
=
NULL
;
static
gchar
*
actual
=
NULL
;
/******************************************************************************
* Fixtures
*****************************************************************************/
static
void
simple_setup
(
void
)
{
tplate
=
gplate_template_new
();
dict
=
gplate_dictionary_variable_new
(
"list"
);
gplate_collection_add_variable
(
GPLATE_COLLECTION
(
tplate
),
dict
);
}
static
void
simple_teardown
(
void
)
{
g_object_unref
(
G_OBJECT
(
tplate
));
g_object_unref
(
G_OBJECT
(
dict
));
g_free
(
actual
);
actual
=
NULL
;
}
/******************************************************************************
* Helpers
*****************************************************************************/
static
void
for_test
(
ForData
*
fd
,
const
gchar
*
tplate_string
,
const
gchar
*
expected
)
{
gint
i
=
0
,
count
=
0
;
/* add the variables */
for
(
i
=
0
,
count
=
0
;
fd
[
i
].
name
;
i
++
,
count
++
)
gplate_collection_add_string
(
dict
,
fd
[
i
].
name
,
fd
[
i
].
value
);
actual
=
gplate_template_render
(
tplate
,
tplate_string
,
NULL
);
test_string
(
expected
,
actual
);
}
/******************************************************************************
* Simple For's
*****************************************************************************/
START_TEST
(
test_for_simple_zero_elements
)
ForData
fd
[]
=
{
{
NULL
,
NULL
},
};
for_test
(
fd
,
"{% for i in list %}{{ i }}{% endfor %}"
,
""
);
END_TEST
START_TEST
(
test_for_simple_one_element
)
ForData
fd
[]
=
{
{
"one"
,
"1"
},
{
NULL
,
NULL
},
};
for_test
(
fd
,
"{% for i in list %}{{ i }}{% endfor %}"
,
"1"
);
END_TEST
START_TEST
(
test_for_simple_two_elements
)
ForData
fd
[]
=
{
{
"a"
,
"A"
},
{
"b"
,
"B"
},
{
NULL
,
NULL
},
};
for_test
(
fd
,
"{% for i in list %}{{ i }}{% endfor %}"
,
"AB"
);
END_TEST
/******************************************************************************
* Exported
*****************************************************************************/
Suite
*
for_suite
(
void
)
{
Suite
*
s
=
suite_create
(
"For Function Suite"
);
TCase
*
tc
=
NULL
;
tc
=
tcase_create
(
"Simple For Loops"
);
tcase_add_checked_fixture
(
tc
,
simple_setup
,
simple_teardown
);
tcase_add_test
(
tc
,
test_for_simple_zero_elements
);
tcase_add_test
(
tc
,
test_for_simple_one_element
);
tcase_add_test
(
tc
,
test_for_simple_two_elements
);
suite_add_tcase
(
s
,
tc
);
return
s
;
}