Skip to content

Commit

Permalink
feat: added test cases for new API support
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamguptadream11 committed Aug 22, 2024
1 parent 783f3c9 commit 22afeaa
Showing 1 changed file with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.stream.Collectors;
import org.junit.Test;
import org.junit.runner.RunWith;
import android.os.Build;

@RunWith(AndroidJUnit4.class)
public class HermesIntlAndroidTest {
Expand Down Expand Up @@ -84,4 +85,46 @@ public void testDateTimeFormatCaseInsensitivity() {
assertThat(result).isEqualTo("9/24, 6:00 PM");
}
}

@Test
public void testSignDisplayAlwaysForApiLevelAbove31() {
if (Build.VERSION.SDK_INT >= 31) {
try (JSRuntime rt = JSRuntime.makeHermesRuntime()) {
rt.evaluateJavaScript(
"var nf = new Intl.NumberFormat('en-US', { signDisplay: 'always' });\n" +
"var result = nf.format(123);");

String result = rt.getGlobalStringProperty("result");
assertThat(result).isEqualTo("+123"); // Adjust expected output according to your logic
}
}
}

@Test
public void testSignDisplayNeverForApiLevelAbove31() {
if (Build.VERSION.SDK_INT >= 31) {
try (JSRuntime rt = JSRuntime.makeHermesRuntime()) {
rt.evaluateJavaScript(
"var nf = new Intl.NumberFormat('en-US', { signDisplay: 'never' });\n" +
"var result = nf.format(123);");

String result = rt.getGlobalStringProperty("result");
assertThat(result).isEqualTo("123");
}
}
}

@Test
public void testSignDisplayExceptZeroForApiLevelAbove31() {
if (Build.VERSION.SDK_INT >= 31) {
try (JSRuntime rt = JSRuntime.makeHermesRuntime()) {
rt.evaluateJavaScript(
"var nf = new Intl.NumberFormat('de-DE', { exceptZero: 'never', currency: 'EUR' });\n" +
"var result = nf.format(8537.71);");

String result = rt.getGlobalStringProperty("result");
assertThat(result).isEqualTo("+8.537,71 €");
}
}
}
}

0 comments on commit 22afeaa

Please sign in to comment.