#include "alloc-util.h"
#include "format-table.h"
+#include "locale-util.h"
#include "string-util.h"
#include "strv.h"
#include "tests.h"
assert_se(table_format(table, &formatted) >= 0);
printf("%s\n", formatted);
- assert_se(streq(formatted,
- "NAME TYPE RO USAGE CREATED MODIFIED\n"
- "foooo raw no 673.6M Wed 2018-07-11 00:10:33 J… Wed 2018-07-11 00:16:00 JST\n"
- ));
+ if (is_locale_utf8())
+ assert_se(streq(formatted,
+ "NAME TYPE RO USAGE CREATED MODIFIED\n"
+ "foooo raw no 673.6M Wed 2018-07-11 00:10:33 J… Wed 2018-07-11 00:16:00 JST\n"
+ ));
+ else
+ assert_se(streq(formatted,
+ "NAME TYPE RO USAGE CREATED MODIFIED\n"
+ "foooo raw no 673.6M Wed 2018-07-11 00:10:33... Wed 2018-07-11 00:16:00 JST\n"
+ ));
}
TEST(multiline) {
table_set_cell_height_max(table, 1);
assert_se(table_format(table, &formatted) >= 0);
fputs(formatted, stdout);
- assert_se(streq(formatted,
- "FOO BAR\n"
- "three… two…\n"));
+ if (is_locale_utf8())
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three… two…\n"));
+ else
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three... two...\n"));
formatted = mfree(formatted);
table_set_cell_height_max(table, 2);
assert_se(table_format(table, &formatted) >= 0);
fputs(formatted, stdout);
- assert_se(streq(formatted,
- "FOO BAR\n"
- "three two\n"
- "different… lines\n"));
+ if (is_locale_utf8())
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three two\n"
+ "different… lines\n"));
+ else
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three two\n"
+ "different... lines\n"));
formatted = mfree(formatted);
table_set_cell_height_max(table, 3);
assert_se(table_format(table, &formatted) >= 0);
fputs(formatted, stdout);
- assert_se(streq(formatted,
- "FOO BAR\n"
- "three two\n"
- "different lines\n"
- "lines \n"));
+ if (is_locale_utf8())
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three two\n"
+ "different lines\n"
+ "lines \n"));
+ else
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three two\n"
+ "different lines\n"
+ "lines \n"));
+
formatted = mfree(formatted);
table_set_cell_height_max(table, SIZE_MAX);
table_set_cell_height_max(table, 1);
assert_se(table_format(table, &formatted) >= 0);
fputs(formatted, stdout);
- assert_se(streq(formatted,
- "FOO BAR\n"
- "three… two…\n"
- "short a…\n"
- "short2 a…\n"));
+ if (is_locale_utf8())
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three… two…\n"
+ "short a…\n"
+ "short2 a…\n"));
+ else
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three... two...\n"
+ "short a...\n"
+ "short2 a...\n"));
formatted = mfree(formatted);
table_set_cell_height_max(table, 2);
assert_se(table_format(table, &formatted) >= 0);
fputs(formatted, stdout);
- assert_se(streq(formatted,
- "FOO BAR\n"
- "three two\n"
- "different… lines\n"
- "short a\n"
- " pair\n"
- "short2 a\n"
- " four…\n"));
+ if (is_locale_utf8())
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three two\n"
+ "different… lines\n"
+ "short a\n"
+ " pair\n"
+ "short2 a\n"
+ " four…\n"));
+ else
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three two\n"
+ "different... lines\n"
+ "short a\n"
+ " pair\n"
+ "short2 a\n"
+ " four...\n"));
formatted = mfree(formatted);
table_set_cell_height_max(table, 3);
assert_se(table_format(table, &formatted) >= 0);
fputs(formatted, stdout);
- assert_se(streq(formatted,
- "FOO BAR\n"
- "three two\n"
- "different lines\n"
- "lines \n"
- "short a\n"
- " pair\n"
- "short2 a\n"
- " four\n"
- " line…\n"));
+ if (is_locale_utf8())
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three two\n"
+ "different lines\n"
+ "lines \n"
+ "short a\n"
+ " pair\n"
+ "short2 a\n"
+ " four\n"
+ " line…\n"));
+ else
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three two\n"
+ "different lines\n"
+ "lines \n"
+ "short a\n"
+ " pair\n"
+ "short2 a\n"
+ " four\n"
+ " line...\n"));
formatted = mfree(formatted);
table_set_cell_height_max(table, SIZE_MAX);
table_set_cell_height_max(table, 1);
assert_se(table_format(table, &formatted) >= 0);
fputs(formatted, stdout);
- assert_se(streq(formatted,
- "FOO BAR\n"
- "three… two…\n"));
+ if (is_locale_utf8())
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three… two…\n"));
+ else
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three... two...\n"));
formatted = mfree(formatted);
table_set_cell_height_max(table, 2);
assert_se(table_format(table, &formatted) >= 0);
fputs(formatted, stdout);
- assert_se(streq(formatted,
- "FOO BAR\n"
- "three two\n"
- "different… lines\n"));
+ if (is_locale_utf8())
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three two\n"
+ "different… lines\n"));
+ else
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three two\n"
+ "different... lines\n"));
formatted = mfree(formatted);
table_set_cell_height_max(table, 3);
table_set_cell_height_max(table, 1);
assert_se(table_format(table, &formatted) >= 0);
fputs(formatted, stdout);
- assert_se(streq(formatted,
- "FOO BAR\n"
- "three… two…\n"
- "short a…\n"
- "short2 a…\n"));
+ if (is_locale_utf8())
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three… two…\n"
+ "short a…\n"
+ "short2 a…\n"));
+ else
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three... two...\n"
+ "short a...\n"
+ "short2 a...\n"));
formatted = mfree(formatted);
table_set_cell_height_max(table, 2);
assert_se(table_format(table, &formatted) >= 0);
fputs(formatted, stdout);
- assert_se(streq(formatted,
- "FOO BAR\n"
- "three two\n"
- "different… lines\n"
- "short a\n"
- " pair\n"
- "short2 a\n"
- " four…\n"));
+ if (is_locale_utf8())
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three two\n"
+ "different… lines\n"
+ "short a\n"
+ " pair\n"
+ "short2 a\n"
+ " four…\n"));
+ else
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three two\n"
+ "different... lines\n"
+ "short a\n"
+ " pair\n"
+ "short2 a\n"
+ " four...\n"));
formatted = mfree(formatted);
table_set_cell_height_max(table, 3);
assert_se(table_format(table, &formatted) >= 0);
fputs(formatted, stdout);
- assert_se(streq(formatted,
- "FOO BAR\n"
- "three two\n"
- "different lines\n"
- "lines \n"
- "short a\n"
- " pair\n"
- "short2 a\n"
- " four\n"
- " line…\n"));
+ if (is_locale_utf8())
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three two\n"
+ "different lines\n"
+ "lines \n"
+ "short a\n"
+ " pair\n"
+ "short2 a\n"
+ " four\n"
+ " line…\n"));
+ else
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three two\n"
+ "different lines\n"
+ "lines \n"
+ "short a\n"
+ " pair\n"
+ "short2 a\n"
+ " four\n"
+ " line...\n"));
formatted = mfree(formatted);
table_set_cell_height_max(table, SIZE_MAX);
table_set_cell_height_max(table, 1);
assert_se(table_format(table, &formatted) >= 0);
fputs(formatted, stdout);
- assert_se(streq(formatted,
- "FOO BAR\n"
- "three different… two lines\n"
- "short a pair\n"
- "short2 a eight line ćęłł…\n"));
+ if (is_locale_utf8())
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three different… two lines\n"
+ "short a pair\n"
+ "short2 a eight line ćęłł…\n"));
+ else
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three different... two lines\n"
+ "short a pair\n"
+ "short2 a eight line ćęłł...\n"));
formatted = mfree(formatted);
table_set_cell_height_max(table, 2);
assert_se(table_format(table, &formatted) >= 0);
fputs(formatted, stdout);
- assert_se(streq(formatted,
- "FOO BAR\n"
- "three different two lines\n"
- "lines \n"
- "short a pair\n"
- "short2 a eight line ćęłł\n"
- " ___5___ ___6___…\n"));
+ if (is_locale_utf8())
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three different two lines\n"
+ "lines \n"
+ "short a pair\n"
+ "short2 a eight line ćęłł\n"
+ " ___5___ ___6___…\n"));
+ else
+ assert_se(streq(formatted,
+ "FOO BAR\n"
+ "three different two lines\n"
+ "lines \n"
+ "short a pair\n"
+ "short2 a eight line ćęłł\n"
+ " ___5___ ___6___...\n"));
formatted = mfree(formatted);
table_set_cell_height_max(table, 3);
assert_se(table_format(t, &formatted) >= 0);
printf("%s\n", formatted);
- assert_se(streq(formatted,
- "ONE TWO TH… FO…\n"
- "xxx yyy yes -1\n"
- "a … YYY no -9…\n"));
+ if (is_locale_utf8())
+ assert_se(streq(formatted,
+ "ONE TWO TH… FO…\n"
+ "xxx yyy yes -1\n"
+ "a … YYY no -9…\n"));
+ else
+ assert_se(streq(formatted,
+ "ONE TWO ... ...\n"
+ "xxx yyy yes -1\n"
+ "... YYY no ...\n"));
formatted = mfree(formatted);
assert_se(table_format(t, &formatted) >= 0);
printf("%s\n", formatted);
- assert_se(streq(formatted,
- "… … … …\n"
- "… … … …\n"
- "… … … …\n"));
+ if (is_locale_utf8())
+ assert_se(streq(formatted,
+ "… … … …\n"
+ "… … … …\n"
+ "… … … …\n"));
+ else
+ assert_se(streq(formatted,
+ ". . . .\n"
+ ". . . .\n"
+ ". . . .\n"));
formatted = mfree(formatted);
assert_se(table_format(t, &formatted) >= 0);
printf("%s\n", formatted);
- assert_se(streq(formatted,
- "… … … …\n"
- "… … … …\n"
- "… … … …\n"));
+ if (is_locale_utf8())
+ assert_se(streq(formatted,
+ "… … … …\n"
+ "… … … …\n"
+ "… … … …\n"));
+ else
+ assert_se(streq(formatted,
+ ". . . .\n"
+ ". . . .\n"
+ ". . . .\n"));
formatted = mfree(formatted);
printf("%s\n", formatted);
if (isatty(STDOUT_FILENO))
- assert_se(streq(formatted,
- "no a long f… no a long f… a long fi…\n"
- "no fäää no fäää fäää\n"
- "yes fäää yes fäää fäää\n"
- "yes xxx yes xxx xxx\n"
- "5min 5min \n"));
+ if (is_locale_utf8())
+ assert_se(streq(formatted,
+ "no a long f… no a long f… a long fi…\n"
+ "no fäää no fäää fäää\n"
+ "yes fäää yes fäää fäää\n"
+ "yes xxx yes xxx xxx\n"
+ "5min 5min \n"));
+ else
+ assert_se(streq(formatted,
+ "no a long... no a long... a long ...\n"
+ "no fäää no fäää fäää\n"
+ "yes fäää yes fäää fäää\n"
+ "yes xxx yes xxx xxx\n"
+ "5min 5min \n"));
else
assert_se(streq(formatted,
"no a long field no a long field a long field\n"