Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
juerg committed Dec 15, 2023
1 parent c8d6e6a commit 96d22c4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,8 @@ else if (v instanceof VncChar) {
.examples(
"(str/join [1 2 3])",
"(str/join \"-\" [1 2 3])",
"(str/join \"-\" [(char \"a\") 1 \"xyz\" 2.56M])")
"(str/join \"-\" [(char \"a\") 1 \"xyz\" 2.56M])",
"(str/join #\\- [1 2 3])")
.build()
) {
@Override
Expand All @@ -926,7 +927,11 @@ public VncVal apply(final VncList args) {
}


final String delim = args.size() == 1 ? "" : Coerce.toVncString(args.first()).getValue();
final String delim = args.size() == 1
? ""
: Types.isVncChar(args.first())
? Coerce.toVncChar(args.first()).toString()
: Coerce.toVncString(args.first()).getValue();

return new VncString(
coll.stream()
Expand Down Expand Up @@ -1889,7 +1894,10 @@ public VncVal apply(final VncList args) {
.examples(
"(str/repeat \"abc\" 0)",
"(str/repeat \"abc\" 3)",
"(str/repeat \"abc\" 3 \"-\")")
"(str/repeat \"abc\" 3 \"-\")",
"(str/repeat #\\* 0)",
"(str/repeat #\\* 3)",
"(str/repeat #\\* 3 #\\-)")
.build()
) {
@Override
Expand All @@ -1900,9 +1908,15 @@ public VncVal apply(final VncList args) {
return Nil;
}

final String s = Coerce.toVncString(args.first()).getValue();
final String s = Types.isVncChar(args.first())
? Coerce.toVncChar(args.first()).toString()
: Coerce.toVncString(args.first()).getValue();
final int times = Coerce.toVncLong(args.second()).getValue().intValue();
final String sep = args.size() == 3 ? Coerce.toVncString(args.nth(2)).getValue() : "";
final String sep = args.size() == 3
? Types.isVncChar(args.third())
? Coerce.toVncChar(args.third()).toString()
: Coerce.toVncString(args.third()).getValue()
: "";

final StringBuilder sb = new StringBuilder();
for(int ii=0; ii<times; ii++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,22 @@ public void test_str_join() {
assertEquals("", venice.eval("(str/join nil)"));
assertEquals("", venice.eval("(str/join \"\" nil)"));
assertEquals("", venice.eval("(str/join \"-\" nil)"));
assertEquals("", venice.eval("(str/join #\\- nil)"));

assertEquals("", venice.eval("(str/join '())"));
assertEquals("", venice.eval("(str/join \"\" '())"));
assertEquals("", venice.eval("(str/join \"-\" '())"));
assertEquals("", venice.eval("(str/join #\\- '())"));

assertEquals("ab", venice.eval("(str/join '(\"ab\"))"));
assertEquals("ab", venice.eval("(str/join \"\" '(\"ab\"))"));
assertEquals("ab", venice.eval("(str/join \"-\" '(\"ab\"))"));
assertEquals("ab", venice.eval("(str/join #\\- '(\"ab\"))"));

assertEquals("abcdef", venice.eval("(str/join '(\"ab\" \"cd\" \"ef\"))"));
assertEquals("abcdef", venice.eval("(str/join \"\" '(\"ab\" \"cd\" \"ef\"))"));
assertEquals("ab-cd-ef", venice.eval("(str/join \"-\" '(\"ab\" \"cd\" \"ef\"))"));
assertEquals("ab-cd-ef", venice.eval("(str/join #\\- '(\"ab\" \"cd\" \"ef\"))"));

assertEquals("abcdef", venice.eval("(str/join (str/chars \"abcdef\"))"));
}
Expand Down Expand Up @@ -332,6 +336,10 @@ public void test_str_repeat() {
assertEquals("", venice.eval("(str/repeat \"abc\" 0)"));
assertEquals("abcabcabc", venice.eval("(str/repeat \"abc\" 3)"));
assertEquals("abc-abc-abc", venice.eval("(str/repeat \"abc\" 3 \"-\")"));

assertEquals("", venice.eval("(str/repeat #\\* 0)"));
assertEquals("***", venice.eval("(str/repeat #\\* 3)"));
assertEquals("*-*-*", venice.eval("(str/repeat #\\* 3 #\\-)"));
}

@Test
Expand Down

0 comments on commit 96d22c4

Please sign in to comment.