diff --git a/Data/String/cork.cpp b/Data/String/cork.cpp index 67c0689..75f5f6d 100644 --- a/Data/String/cork.cpp +++ b/Data/String/cork.cpp @@ -29,12 +29,11 @@ contains_unicode_char (string s) { string tm_encode (string s) { // verbatim to TeXmacs encoding - int i; string r; - for (i= 0; i < N (s); i++) { - if (s[i] == '<') r << ""; - else if (s[i] == '>') r << ""; - else r << s[i]; + for (const auto ch : s) { + if (ch == '<') r << ""; + else if (ch == '>') r << ""; + else r << ch; } return r; } diff --git a/tests/Data/String/cork_test.cpp b/tests/Data/String/cork_test.cpp new file mode 100644 index 0000000..1c47572 --- /dev/null +++ b/tests/Data/String/cork_test.cpp @@ -0,0 +1,22 @@ + +/****************************************************************************** + * MODULE : cork_test.cpp + * DESCRIPTION: tests for the Cork encoding + * COPYRIGHT : (C) 2024 Darcy Shen + ******************************************************************************* + * This software falls under the GNU general public license version 3 or later. + * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE + * in the root directory or . + ******************************************************************************/ + +#include "cork.hpp" +#include "modification.hpp" +#include "moe_doctests.hpp" +#include "tree.hpp" + +TEST_CASE ("tm_encode") { + string_eq (tm_encode ("<>"), ""); + string_eq (tm_encode ("<#ABCD>"), "#ABCD"); + string_eq (tm_encode ("abc"), "abc"); + string_eq (tm_encode (""), ""); +}