Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extended matcher to allow for new definition of num-dot-decimal where… #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/io/datanapis/xbrl/utils/IxtTransform.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class IxtTransform {
Pattern.compile("^[ \\t\\n\\r]*([-]|\u002D|\u058A|\u05BE|\u2010|\u2011|\u2012|\u2013|\u2014|\u2015|\uFE58|\uFE63|\uFF0D)[ \\t\\n\\r]*$");

private static final Pattern NUM_DOT_DECIMAL =
Pattern.compile("^[ \\t\\n\\r]*[0-9]{1,3}([, \u00A0]?[0-9]{3})*(\\.[0-9]+)?[ \\t\\n\\r]*$");
Pattern.compile("^[ \\t\\n\\r]*[0-9]{1,3}([, \u00A0]?[0-9]{3})*(\\.[0-9]+)?[ \\t\\n\\r]*$|^[ \\t\\n\\r]*(\\.[0-9]+)[ \\t\\n\\r]*$");

private static final Pattern NUM_DOT_DECIMAL_IN =
Pattern.compile("^(([0-9]{1,2}[, \u00A0])?([0-9]{2}[, \u00A0])*[0-9]{3})([.][0-9]+)?$|^([0-9]+)([.][0-9]+)?$");
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/io/datanapis/test/IxtTransformTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,41 @@
package io.datanapis.test;

import io.datanapis.xbrl.utils.IxtTransform;
import org.junit.Assert;
import org.junit.Test;

public class IxtTransformTest {

public static final String NUMBER_WITH_SPACE_AND_DECIMALS = "1 123.23";
public static final String NUMBER_WITH_COMMA_AND_DECIMALS = "1,123.23";
public static final String NUMBER_AND_DECIMALS = "1,123.23";
public static final String DECIMALS_ONLY = ".23";
public static final String NUM_DOT_DECIMAL_FORMAT = "num-dot-decimal";

@Test
public void testTransform() {
String value = IxtTransform.parseDate("October 2026", "datemonthyearen");
System.out.println(value);
}

@Test
public void testTransformNumberWithDecimals() {
final String expectedNumberAndDecimal = "1123.23";
Assert.assertEquals(expectedNumberAndDecimal,
IxtTransform.transformWithFormat(NUM_DOT_DECIMAL_FORMAT, NUMBER_WITH_SPACE_AND_DECIMALS));

Assert.assertEquals(expectedNumberAndDecimal,
IxtTransform.transformWithFormat(NUM_DOT_DECIMAL_FORMAT, NUMBER_WITH_COMMA_AND_DECIMALS));

Assert.assertEquals(expectedNumberAndDecimal,
IxtTransform.transformWithFormat(NUM_DOT_DECIMAL_FORMAT, NUMBER_AND_DECIMALS));

}

@Test
public void testTransformDecimalsOnly() {
final String expectedNumberAndDecimal = ".23";
Assert.assertEquals(expectedNumberAndDecimal,
IxtTransform.transformWithFormat(NUM_DOT_DECIMAL_FORMAT, DECIMALS_ONLY));
}
}