fix: allow (`int` corresponding of) unicode value for `Chr` builtin fct

That fixes partialy #1571.
This commit is contained in:
The-Lum 2023-12-08 21:20:22 +00:00
parent 1cb61d5609
commit 3f836a44cc
2 changed files with 5 additions and 5 deletions

View File

@ -59,8 +59,8 @@ public class Chr extends SimpleReturnFunction {
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
try {
final char value = (char) values.get(0).toInt();
return TValue.fromString("" + value);
final String value = String.valueOf(Character.toChars(values.get(0).toInt()));
return TValue.fromString(value);
} catch (Throwable t) {
return TValue.fromString("\0");
}

View File

@ -32,9 +32,9 @@ class ChrTest {
" 34 , '\"' ",
" 224 , à ",
" 233 , é ",
// TODO: fix `%chr` to allow Unicode chars, the corresponding tests are here:
// " 128512 , 😀 ",
// " 128512 , \uD83D\uDE00 ",
// DONE: fix `%chr` to allow Unicode chars, the corresponding tests are here:
" 128512 , 😀 ",
" 128512 , \uD83D\uDE00 ",
})
void executeReturnFunctionChrTest(Integer input, String expected) throws EaterException, EaterExceptionLocated {
Chr cut = new Chr();