extern Uzbl uzbl;
extern gchar* expand(char*, guint, gboolean);
-extern gchar* expand_template(const char*, gboolean);
extern void make_var_to_name_hash(void);
void
-test_URI (void) {
+test_uri (void) {
+ g_assert_cmpstr(expand("@uri", 0, FALSE), ==, "");
+
uzbl.state.uri = g_strdup("http://www.uzbl.org/");
- g_assert_cmpstr(expand_template("URI", FALSE), ==, uzbl.state.uri);
+ g_assert_cmpstr(expand("@uri", 0, FALSE), ==, uzbl.state.uri);
g_free(uzbl.state.uri);
}
void
test_LOAD_PROGRESS (void) {
uzbl.gui.sbar.load_progress = 50;
- g_assert_cmpstr(expand_template("LOAD_PROGRESS", FALSE), ==, "50");
+ g_assert_cmpstr(expand("@LOAD_PROGRESS", 0, FALSE), ==, "50");
}
void
test_LOAD_PROGRESSBAR (void) {
- uzbl.gui.sbar.load_progress = 75;
uzbl.gui.sbar.progress_w = 4;
+ progress_change_cb(NULL, 75, NULL);
- uzbl.gui.sbar.progress_s = "*";
- uzbl.gui.sbar.progress_u = "-";
-
- g_assert_cmpstr(expand_template("LOAD_PROGRESSBAR", FALSE), ==, "***-");
+ g_assert_cmpstr(expand("@LOAD_PROGRESSBAR", 0, FALSE), ==, "===ยท");
}
void
test_TITLE (void) {
uzbl.gui.main_title = "Lorem Ipsum";
- g_assert_cmpstr(expand_template("TITLE", FALSE), ==, "Lorem Ipsum");
+ g_assert_cmpstr(expand("@TITLE", 0, FALSE), ==, "Lorem Ipsum");
}
void
test_SELECTED_URI (void) {
uzbl.state.selected_url = "http://example.org/";
- g_assert_cmpstr(expand_template("SELECTED_URI", FALSE), ==, "http://example.org/");
+ g_assert_cmpstr(expand("@SELECTED_URI", 0, FALSE), ==, "http://example.org/");
}
void
test_NAME (void) {
- uzbl.state.instance_name = "12345";
- g_assert_cmpstr(expand_template("NAME", FALSE), ==, "12345");
+ uzbl.state.instance_name = "testing";
+ g_assert_cmpstr(expand("@NAME", 0, FALSE), ==, "testing");
}
void
test_KEYCMD (void) {
uzbl.state.keycmd = g_string_new("gg winslow");
- g_assert_cmpstr(expand_template("KEYCMD", FALSE), ==, "gg winslow");
+ g_assert_cmpstr(expand("@KEYCMD", 0, FALSE), ==, "gg winslow");
g_string_free(uzbl.state.keycmd, TRUE);
}
void
test_MODE (void) {
- uzbl.behave.cmd_indicator = "C";
- uzbl.behave.insert_indicator = "I";
-
- uzbl.behave.insert_mode = 0;
- g_assert_cmpstr(expand_template("MODE", FALSE), ==, "C");
+ set_insert_mode(FALSE);
+ g_assert_cmpstr(expand("@MODE", 0, FALSE), ==, "C");
- uzbl.behave.insert_mode = 1;
- g_assert_cmpstr(expand_template("MODE", FALSE), ==, "I");
+ set_insert_mode(TRUE);
+ g_assert_cmpstr(expand("@MODE", 0, FALSE), ==, "I");
}
void
test_MSG (void) {
uzbl.gui.sbar.msg = "Hello from frosty Edmonton!";
- g_assert_cmpstr(expand_template("MSG", FALSE), ==, "Hello from frosty Edmonton!");
+ g_assert_cmpstr(expand("@MSG", 0, FALSE), ==, "Hello from frosty Edmonton!");
}
void
g_free(uzbl.state.uri);
}
+void
+test_escape_expansion (void) {
+ /* \@ -> @ */
+ g_assert_cmpstr(expand("\\@uri", 0, FALSE), ==, "@uri");
+
+ /* \\\@ -> \@ */
+ g_assert_cmpstr(expand("\\\\\\@uri", 0, FALSE), ==, "\\@uri");
+
+ /* \@(...)\@ -> @(...)@ */
+ g_assert_cmpstr(expand("\\@(echo hi)\\@", 0, FALSE), ==, "@(echo hi)@");
+
+ /* \@<...>\@ -> @<...>@ */
+ g_assert_cmpstr(expand("\\@<\"hi\">\\@", 0, FALSE), ==, "@<\"hi\">@");
+}
+
+void
+test_nested (void) {
+ uzbl.gui.sbar.msg = "xxx";
+ g_assert_cmpstr(expand("@<\"..@MSG..\">@", 0, FALSE), ==, "..xxx..");
+ g_assert_cmpstr(expand("@<\"..\\@MSG..\">@", 0, FALSE), ==, "..@MSG..");
+
+ g_assert_cmpstr(expand("@(echo ..@MSG..)@", 0, FALSE), ==, "..xxx..");
+ g_assert_cmpstr(expand("@(echo ..\\@MSG..)@", 0, FALSE), ==, "..@MSG..");
+}
+
int
main (int argc, char *argv[]) {
g_type_init();
g_test_init(&argc, &argv, NULL);
- g_test_add_func("/test-expand/URI", test_URI);
- g_test_add_func("/test-expand/LOAD_PROGRESS", test_LOAD_PROGRESS);
- g_test_add_func("/test-expand/LOAD_PROGRESSBAR", test_LOAD_PROGRESSBAR);
- g_test_add_func("/test-expand/TITLE", test_TITLE);
- g_test_add_func("/test-expand/SELECTED_URI", test_SELECTED_URI);
- g_test_add_func("/test-expand/NAME", test_NAME);
- g_test_add_func("/test-expand/KEYCMD", test_KEYCMD);
- g_test_add_func("/test-expand/MODE", test_MODE);
- g_test_add_func("/test-expand/MSG", test_MSG);
- g_test_add_func("/test-expand/WEBKIT_VERSION", test_WEBKIT_VERSION);
- g_test_add_func("/test-expand/ARCH_UZBL", test_ARCH_UZBL);
- g_test_add_func("/test-expand/COMMIT", test_COMMIT);
+ g_test_add_func("/test-expand/@uri", test_uri);
+ g_test_add_func("/test-expand/@LOAD_PROGRESS", test_LOAD_PROGRESS);
+ g_test_add_func("/test-expand/@LOAD_PROGRESSBAR", test_LOAD_PROGRESSBAR);
+ g_test_add_func("/test-expand/@TITLE", test_TITLE);
+ g_test_add_func("/test-expand/@SELECTED_URI", test_SELECTED_URI);
+ g_test_add_func("/test-expand/@NAME", test_NAME);
+// g_test_add_func("/test-expand/@KEYCMD", test_KEYCMD);
+ g_test_add_func("/test-expand/@MODE", test_MODE);
+ g_test_add_func("/test-expand/@MSG", test_MSG);
+ g_test_add_func("/test-expand/@WEBKIT_*", test_WEBKIT_VERSION);
+ g_test_add_func("/test-expand/@ARCH_UZBL", test_ARCH_UZBL);
+ g_test_add_func("/test-expand/@COMMIT", test_COMMIT);
g_test_add_func("/test-expand/cmd_useragent_simple", test_cmd_useragent_simple);
g_test_add_func("/test-expand/cmd_useragent_full", test_cmd_useragent_full);
g_test_add_func("/test-expand/escape_markup", test_escape_markup);
+ g_test_add_func("/test-expand/escape_expansion", test_escape_expansion);
+ g_test_add_func("/test-expand/nested", test_nested);
initialize(argc, argv);