Skip to content

Commit

Permalink
Add unit test for #4 - Magic chars in StringPattern character groups …
Browse files Browse the repository at this point in the history
…behaving incorrectly
  • Loading branch information
mkarneim committed May 5, 2019
1 parent 6f90e02 commit 12c8645
Showing 1 changed file with 99 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package net.sandius.rembulan.lib;

import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

import net.sandius.rembulan.testenv.TestBase;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class StringLib_Issue_4_Test extends TestBase {
@Test
public void _test_a_match_a() throws Exception {
// Given:
String program = "return string.match(\"a\",\"a\")";

// When:
Object[] actual = run(program);

// Then:
assertThat(actual).isEqualTo(new Object[] {"a"});
}

@Test
public void _test_1_match_not_1() throws Exception {

// Given:
String program = "return string.match(\"1\",\"[^1]\")";

// When:
Object[] actual = run(program);

// Then:
assertThat(actual).isEqualTo(new Object[] {null});
}

@Test
public void _test_1_match_not_0() throws Exception {

// Given:
String program = "return string.match(\"1\",\"[^0]\")";

// When:
Object[] actual = run(program);

// Then:
assertThat(actual).isEqualTo(new Object[] {"1"});
}

@Test
public void _test_1_match_1() throws Exception {

// Given:
String program = "return string.match(\"1\",\"[1]\")";

// When:
Object[] actual = run(program);

// Then:
assertThat(actual).isEqualTo(new Object[] {"1"});
}

@Test
public void _test_1_match_0() throws Exception {

// Given:
String program = "return string.match(\"1\",\"[0]\")";

// When:
Object[] actual = run(program);

// Then:
assertThat(actual).isEqualTo(new Object[] {null});
}

@Test
public void _test_plus_match_plus() throws Exception {

// Given:
String program = "return string.match(\"+\",\"[+]\")";

// When:
Object[] actual = run(program);

// Then:
assertThat(actual).isEqualTo(new Object[] {null});
}

@Test
public void test() throws Exception {
// Given:
String program = "string.match(tostring(0.5), \"([^05+])\")";

// When:
Object[] actual = run(program);

// Then:
assertThat(actual).isEqualTo(new Object[] {"."});
}
}

0 comments on commit 12c8645

Please sign in to comment.