Skip to content
Permalink
Browse files
Fix extraneous bare string warnings in tests
  • Loading branch information
PseudoKnight committed May 24, 2020
1 parent 2c6dbab commit f111a7a8c97cdda79b729c5de7081e9219f89018
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 79 deletions.
@@ -187,7 +187,7 @@ public void testCompile15() throws Exception {

@Test
public void testExecute1() throws Exception {
String script = "proc(_hello, @hello0,"
String script = "proc('_hello', @hello0,"
+ " msg(@hello0)"
+ " )"
+ " assign(@hello1, 'hello')"
@@ -200,7 +200,7 @@ public void testExecute1() throws Exception {
@Test
public void testExecute2() throws Exception {
String script
= "proc(_hello,\n"
= "proc('_hello',\n"
+ " assign(@hello, 'hello')\n"
+ " return(@hello)\n"
+ ")\n"
@@ -238,7 +238,7 @@ public void testExecute3() {
@Test
public void testExecute4() throws Exception {
String script
= "proc(_hello,"
= "proc('_hello',"
+ " return('hello')"
+ ")"
+ "msg(_hello())";
@@ -308,7 +308,7 @@ public void testExecute13() throws Exception {
@Test
public void testExecute14() throws Exception {
String script
= "proc(_hello, assign(@i, 'world'),"
= "proc('_hello', assign(@i, 'world'),"
+ " return(@i)"
+ ")"
+ "msg(_hello('hello'))"
@@ -323,7 +323,7 @@ public void testExecute15() throws Exception {
String script
= "assign(@i, 0)\n"
+ "msg('@i is currently' @i)\n"
+ "proc(_out, @i,\n"
+ "proc('_out', @i,\n"
+ " msg(trim('@i is currently' @i 'and @j is' @j))\n"
+ ")\n"
+ "_out('hello')\n"
@@ -338,7 +338,7 @@ public void testExecute15() throws Exception {
@Test
public void testExecute16() throws Exception {
String script
= "proc(_myProc, @i, @j, @k, msg(trim(@i @j @k)))\n"
= "proc('_myProc', @i, @j, @k, msg(trim(@i @j @k)))\n"
+ "_myProc()\n"
+ "_myProc(1)\n"
+ "_myProc(1, 2)\n"
@@ -353,7 +353,7 @@ public void testExecute16() throws Exception {
@Test
public void testExecute17() throws Exception {
String script
= "proc(_addition, @i, @j, msg(add(@i, @j)))\n"
= "proc('_addition', @i, @j, msg(add(@i, @j)))\n"
+ "_addition(1, 1)\n"
+ "_addition(2, 2)";
MethodScriptCompiler.execute(MethodScriptCompiler.compile(MethodScriptCompiler.lex(script, null, null, true), null, envs), env, null, null);
@@ -365,7 +365,7 @@ public void testExecute17() throws Exception {
@Test
public void testExecute18() throws Exception {
String script
= "proc(_myProc, msg(@arguments))\n"
= "proc('_myProc', msg(@arguments))\n"
+ "_myProc()\n"
+ "_myProc(1)\n"
+ "_myProc(1, 2)";
@@ -385,7 +385,7 @@ public void testExecute18() throws Exception {
public void testExecute19() throws Exception {
String script
= "assign(@j, 'world')\n"
+ "proc(_hello, assign(@i, @j),"
+ "proc('_hello', assign(@i, @j),"
+ " return(@i)"
+ ")\n"
+ "assign(@j, 'goodbye')\n"
@@ -400,7 +400,7 @@ public void testExecute19() throws Exception {
public void testExecute20() throws Exception {
final AtomicBoolean bool = new AtomicBoolean(false);
String script
= "msg('hello') world";
= "msg('hello') 'world'";
MethodScriptCompiler.execute(MethodScriptCompiler.compile(MethodScriptCompiler.lex(script, null, null, true), null, envs), env, new MethodScriptComplete() {

@Override
@@ -424,7 +424,7 @@ public void testExecute21() throws Exception {

@Test
public void testExecute22() throws Exception {
SRun("msg('hi' (this is a thing))", fakePlayer);
SRun("msg('hi' ('this is a thing'))", fakePlayer);
verify(fakePlayer).sendMessage("hi this is a thing");
}

@@ -505,7 +505,7 @@ public void testCompile5() throws Exception {
@Test
public void testCompile6() throws Exception {
String config = "/cmd = >>>\n"
+ "msg(trim(hello 'world \\\\ \\' \\n'))"
+ "msg(trim('hello' 'world \\\\ \\' \\n'))"
+ "<<<";
RunCommand(config, fakePlayer, "/cmd");
verify(fakePlayer).sendMessage("hello world \\ '");
@@ -514,7 +514,7 @@ public void testCompile6() throws Exception {
@Test
public void testCompile7() throws Exception {
String config = "/cmd = >>>\n"
+ "msg(hello) \\ msg(world)"
+ "msg('hello') \\ msg('world')"
+ "<<<";
RunCommand(config, fakePlayer, "/cmd");
verify(fakePlayer).sendMessage("hello");
@@ -208,15 +208,15 @@ public void testRange() throws Exception {

@Test
public void testArraySliceAndNegativeIndexes() throws Exception {
assertEquals("{a, b}", SRun("array(a, b, c, d, e)[..1]", null));
assertEquals("e", SRun("array(a, e)[-1]", null));
assertEquals("{a, b, c, d, e}", SRun("array(a, b, c, d, e)[]", null));
assertEquals("{b, c}", SRun("array(a, b, c, d, e)[1..2]", null));
assertEquals("{b, c, d, e}", SRun("array(a, b, c, d, e)[1..-1]", null));
assertEquals("1", SRun("array(a, array(1, 2), c, d, e)[0..1][1][0]", null));
assertEquals("{c, d, e}", SRun("array(a, b, c, d, e)[2..]", null));
assertEquals("{a, b}", SRun("array('a', 'b', 'c', 'd', 'e')[..1]", null));
assertEquals("e", SRun("array('a', 'e')[-1]", null));
assertEquals("{a, b, c, d, e}", SRun("array('a', 'b', 'c', 'd', 'e')[]", null));
assertEquals("{b, c}", SRun("array('a', 'b', 'c', 'd', 'e')[1..2]", null));
assertEquals("{b, c, d, e}", SRun("array('a', 'b', 'c', 'd', 'e')[1..-1]", null));
assertEquals("1", SRun("array('a', array(1, 2), 'c', 'd', 'e')[0..1][1][0]", null));
assertEquals("{c, d, e}", SRun("array('a', 'b', 'c', 'd', 'e')[2..]", null));
assertEquals("{}", SRun("array(1, 2, 3, 4, 5)[3..0]", null));
assertEquals("{a, b}", SRun("array_get(array(a, b))", null));
assertEquals("{a, b}", SRun("array_get(array('a', 'b'))", null));
assertEquals("{2, 3}", SRun("array(1, 2, 3)[1..-1]", null));
assertEquals("{2}", SRun("array(1, 2)[1..-1]", null));
assertEquals("{}", SRun("array(1)[1..-1]", null));
@@ -229,14 +229,15 @@ public void testArrayMergeNormal() throws Exception {

@Test(timeout = 10000)
public void testArrayMergeAssociative() throws Exception {
assertEquals("{a: a, b: b, c: c, d: {1, 2}}", SRun("array_merge(array(a: a, b: b), array(c: c, d: array(1, 2)))", fakePlayer));
assertEquals("{a: a, b: b, c: c, d: {1, 2}}",
SRun("array_merge(array(a: 'a', b: 'b'), array(c: 'c', d: array(1, 2)))", fakePlayer));
}

@Test(timeout = 10000)
public void testArrayRemove() throws Exception {
SRun("assign(@a, array(1, 2, 3)) array_remove(@a, 1) msg(@a)", fakePlayer);
verify(fakePlayer).sendMessage("{1, 3}");
SRun("assign(@a, array(a: a, b: b, c: c)) array_remove(@a, 'b') msg(@a)", fakePlayer);
SRun("assign(@a, array(a: 'a', b: 'b', c: 'c')) array_remove(@a, 'b') msg(@a)", fakePlayer);
verify(fakePlayer).sendMessage("{a: a, c: c}");
}

@@ -290,7 +291,7 @@ public void testArraySort2() throws Exception {

@Test
public void testArraySort3() throws Exception {
Run("msg(array_sort(array('002', '1', '03'), STRING))", fakePlayer);
Run("msg(array_sort(array('002', '1', '03'), 'STRING'))", fakePlayer);
verify(fakePlayer).sendMessage("{002, 03, 1}");
}

@@ -506,29 +507,29 @@ public void testArrayReverse() throws Exception {
public void testArrayIntersect() throws Exception {
assertThat(SRun("array_intersect(array(one: 1, two: 2), array(one: 1, three: 3))", fakePlayer), is("{one: 1}"));
try {
SRun("array_intersect(array(one: 1, two: 2), array(one: 1, three: 3), EQUALS)", fakePlayer);
SRun("array_intersect(array(one: 1, two: 2), array(one: 1, three: 3), 'EQUALS')", fakePlayer);
fail("Did not expect 3 arguments to pass");
} catch (CREIllegalArgumentException e) {
// Pass
}


assertThat(SRun("array_intersect(array(1, 2, 3), array(2, 3, 4), HASH)", fakePlayer), is("{2, 3}"));
assertThat(SRun("array_intersect(array(1, 2, 3), array(4, 5, 6), HASH)", fakePlayer), is("{}"));
assertThat(SRun("array_intersect(array(1, 2, 3), array(2, 3, 4), 'HASH')", fakePlayer), is("{2, 3}"));
assertThat(SRun("array_intersect(array(1, 2, 3), array(4, 5, 6), 'HASH')", fakePlayer), is("{}"));

assertThat(SRun("array_intersect(array(1, 2, 3), array(2, 3, 4), EQUALS)", fakePlayer), is("{2, 3}"));
assertThat(SRun("array_intersect(array(1, 2, 3), array(4, 5, 6), EQUALS)", fakePlayer), is("{}"));
assertThat(SRun("array_intersect(array(1, 2, 3), array(2, 3, 4), 'EQUALS')", fakePlayer), is("{2, 3}"));
assertThat(SRun("array_intersect(array(1, 2, 3), array(4, 5, 6), 'EQUALS')", fakePlayer), is("{}"));

assertThat(SRun("array_intersect(array('1', '2', '3'), array(1, 2, 3), STRICT_EQUALS)", fakePlayer), is("{}"));
assertThat(SRun("array_intersect(array('1', '2', '3'), array('1', 2, 3), STRICT_EQUALS)", fakePlayer), is("{1}"));
assertThat(SRun("array_intersect(array('1', '2', '3'), array(1, 2, 3), 'STRICT_EQUALS')", fakePlayer), is("{}"));
assertThat(SRun("array_intersect(array('1', '2', '3'), array('1', 2, 3), 'STRICT_EQUALS')", fakePlayer), is("{1}"));

assertThat(SRun("array_intersect(array(1, 2, 3), array(4, 5, 6), closure(@a, @b) { return(true); })", fakePlayer),
is("{1, 2, 3}"));
assertThat(SRun("array_intersect(array(1, 2, 3), array(1, 2, 3), closure(@a, @b) { return(false); })", fakePlayer),
is("{}"));

assertThat(SRun("array_intersect(array(array(id: 1, qty: 2), array(id: 2, qty: 8)),"
+ " array(array(id: 1, qty: 19), array(id: 6, qty: 2)), closure(@a, @b){ return(@a[id] == @b[id]); })", fakePlayer),
+ " array(array(id: 1, qty: 19), array(id: 6, qty: 2)), closure(@a, @b){ return(@a['id'] == @b['id']); })", fakePlayer),
is("{{id: 1, qty: 2}}"));

}
@@ -163,13 +163,13 @@ public void testEqualsIC() throws Exception {

@Test(timeout = 10000)
public void testAnd1() throws Exception {
SRun("if(and(true, true, true), msg(pass))", fakePlayer);
SRun("if(and(true, true, false), '', msg(pass))", fakePlayer);
SRun("if(and(true, true), msg(pass))", fakePlayer);
SRun("if(and(true, false), '', msg(pass))", fakePlayer);
SRun("if(and(false, false), '', msg(pass))", fakePlayer);
SRun("if(and(true), msg(pass))", fakePlayer);
SRun("if(and(false), '', msg(pass))", fakePlayer);
SRun("if(and(true, true, true), msg('pass'))", fakePlayer);
SRun("if(and(true, true, false), '', msg('pass'))", fakePlayer);
SRun("if(and(true, true), msg('pass'))", fakePlayer);
SRun("if(and(true, false), '', msg('pass'))", fakePlayer);
SRun("if(and(false, false), '', msg('pass'))", fakePlayer);
SRun("if(and(true), msg('pass'))", fakePlayer);
SRun("if(and(false), '', msg('pass'))", fakePlayer);
verify(fakePlayer, times(7)).sendMessage("pass");
}

@@ -181,25 +181,25 @@ public void testAnd1() throws Exception {
*/
@Test(timeout = 10000)
public void testAnd2() throws Exception {
SRun("and(false, msg(lol))", fakePlayer);
SRun("and(false, msg('lol'))", fakePlayer);
verify(fakePlayer, times(0)).sendMessage("lol");
}

@Test(timeout = 10000)
public void testOr1() throws Exception {
SRun("if(or(true, true, true), msg(pass))", fakePlayer);
SRun("if(or(true, true, false), msg(pass))", fakePlayer);
SRun("if(or(true, true), msg(pass))", fakePlayer);
SRun("if(or(true, false), msg(pass))", fakePlayer);
SRun("if(or(false, false), '', msg(pass))", fakePlayer);
SRun("if(or(true), msg(pass))", fakePlayer);
SRun("if(or(false), '', msg(pass))", fakePlayer);
SRun("if(or(true, true, true), msg('pass'))", fakePlayer);
SRun("if(or(true, true, false), msg('pass'))", fakePlayer);
SRun("if(or(true, true), msg('pass'))", fakePlayer);
SRun("if(or(true, false), msg('pass'))", fakePlayer);
SRun("if(or(false, false), '', msg('pass'))", fakePlayer);
SRun("if(or(true), msg('pass'))", fakePlayer);
SRun("if(or(false), '', msg('pass'))", fakePlayer);
verify(fakePlayer, times(7)).sendMessage("pass");
}

@Test(timeout = 10000)
public void testOr2() throws Exception {
SRun("or(true, msg(lol))", fakePlayer);
SRun("or(true, msg('lol'))", fakePlayer);
verify(fakePlayer, times(0)).sendMessage("lol");
}

@@ -84,15 +84,15 @@ public void testIfelse() throws Exception {
@Test(timeout = 10000)
public void testSwitch() throws Exception {
assertEquals("correct", SRun("switch(3,"
+ "1, wrong,"
+ "2, wrong,"
+ "3, correct,"
+ "4, wrong)", null));
+ "1, 'wrong',"
+ "2, 'wrong',"
+ "3, 'correct',"
+ "4, 'wrong')", null));
assertEquals("correct", SRun("switch(4,"
+ "1, wrong,"
+ "2, wrong,"
+ "3, wrong,"
+ "correct)", null));
+ "1, 'wrong',"
+ "2, 'wrong',"
+ "3, 'wrong',"
+ "'correct')", null));
}

@Test
@@ -116,16 +116,16 @@ public void testSwitch3() throws Exception {
@Test(timeout = 10000)
public void testSwitchWithArray() throws Exception {
assertEquals("correct", SRun("switch(3,"
+ "array(1, 2), wrong,"
+ "array(3, 4), correct,"
+ "5, wrong)", null));
+ "array(1, 2), 'wrong',"
+ "array(3, 4), 'correct',"
+ "5, 'wrong')", null));
}

@Test(timeout = 10000)
public void testSwitchWithNestedArrayAsDefaultReturn() throws Exception {
assertEquals("{{correct}}", SRun("switch(5,"
+ "'case1', wrong,"
+ "'case2', also wrong,"
+ "'case1', 'wrong',"
+ "'case2', 'also wrong',"
+ " array(array('correct')))", null));
}

@@ -35,7 +35,7 @@ public void tearDown() {

@Test(timeout = 10000)
public void testRot13() throws Exception {
assertEquals("hello world", SRun("rot13(uryyb jbeyq)", null));
assertEquals("hello world", SRun("rot13('uryyb jbeyq')", null));
}

@Test(timeout = 10000)
@@ -66,12 +66,12 @@ public void tearDown() {
public void testCallProcIsProc() throws Exception {
when(fakePlayer.isOp()).thenReturn(true);
String config = "/for = >>>\n"
+ " msg(is_proc(_proc))\n"
+ " proc(_proc,"
+ " msg(is_proc('_proc'))\n"
+ " proc('_proc',"
+ " msg('hello world')"
+ " )"
+ " msg(is_proc(_proc))"
+ " call_proc(_proc)"
+ " msg(is_proc('_proc'))"
+ " call_proc('_proc')"
+ "<<<\n";
RunCommand(config, fakePlayer, "/for");
verify(fakePlayer).sendMessage("false");
@@ -124,7 +124,7 @@ public void testExportImportStringValue2() throws Exception {

@Test
public void testExportImportWithProcs1() throws Exception {
SRun("proc(_derping,"
SRun("proc('_derping',"
+ " msg(import('borked'))"
+ " assign(@var, import('borked'))"
+ " assign(@var, array('Am', 'I', 'borked?'))"
@@ -141,7 +141,7 @@ public void testExportImportWithProcs1() throws Exception {
public void testExportImportWithProcs2() throws Exception {
SRun("assign(@array, array(1, 2))"
+ "export('myarray', @array)", fakePlayer);
SRun("proc(_get, return(import('myarray')))"
SRun("proc('_get', return(import('myarray')))"
+ "msg(_get())", fakePlayer);
verify(fakePlayer).sendMessage("{1, 2}");
}
@@ -272,7 +272,7 @@ public void testClosure7() throws Exception {
@Test(timeout = 10000)
public void testClosure8() throws Exception {
when(fakePlayer.isOp()).thenReturn(true);
SRun("execute(Hello, World, closure(msg(@arguments)))", fakePlayer);
SRun("execute('Hello', 'World', closure(msg(@arguments)))", fakePlayer);
verify(fakePlayer).sendMessage("{Hello, World}");
}

@@ -349,13 +349,13 @@ public void testEmptyClosureFunction() throws Exception {

@Test
public void testAssignmentTypes1() throws Exception {
SRun("string @ivar = 'value'", null);
SRun("string @ivar1 = 'value'", null);
}

@Test
public void testAssignmentTypes2() throws Exception {
try {
SRun("array @ivar = 'value'", null);
SRun("array @ivar2 = 'value'", null);
fail("Excepted a CastException because string is not array");
} catch (CRECastException ex) {
// Test passed.
@@ -365,7 +365,7 @@ public void testAssignmentTypes2() throws Exception {
@Test
public void testAssignmentTypes3() throws Exception {
try {
SRun("void @ivar = 'value'", null);
SRun("void @ivar3 = 'value'", null);
fail("Expected a compile exception because IVariable cannot be assigned to void");
} catch (ConfigCompileException ex) {
// Test passed.

0 comments on commit f111a7a

Please sign in to comment.