Exemple #1
0
  @Test
  public void testRemoveNestedVariantConditional() throws Exception {
    String input =
        "if( vObject && vObject.__disposed === false ) {\n"
            + "  try {\n"
            + "    vObject.dispose();\n"
            + "  }\n"
            + "  catch( ex ) {\n"
            + "    if( rwt.util.Variant.isSet( \"qx.debug\", \"on\" ) ) {\n"
            + "      qx.core.Log.warn( \"Could not dispose: \" + vObject + \":\", ex );\n"
            + "    }\n"
            + "  }\n"
            + "}\n";
    String expected =
        "if ( vObject && vObject.__disposed === false ) {\n"
            + "  try {\n"
            + "    vObject.dispose ( );\n"
            + "  }\n"
            + "  catch ( ex ) {\n"
            + "  }\n"
            + "}";
    TokenList tokens = TestUtil.parse(input);

    QxCodeCleaner cleaner = new QxCodeCleaner(tokens);
    cleaner.cleanupQxCode();

    assertEquals(expected, JavaScriptPrinter.printTokens(tokens));
  }
Exemple #2
0
  @Test
  public void testRemoveMultipleVariantConditionals() throws Exception {
    String input = "if( rwt.util.Variant.isSet( \"qx.debug\", \"on\" ) ) {\n}\n";
    TokenList tokens = TestUtil.parse(input);

    QxCodeCleaner cleaner = new QxCodeCleaner(tokens);
    cleaner.cleanupQxCode();

    assertEquals(0, tokens.size());
  }
Exemple #3
0
  @Test
  public void testReplaceBaseCallWithParameters() throws Exception {
    String input = "result = this.base( arguments, 23, 'foo' );";
    TokenList tokens = TestUtil.parse(input);

    QxCodeCleaner cleaner = new QxCodeCleaner(tokens);
    cleaner.cleanupQxCode();

    String expected = "result = arguments.callee.base.call ( this, 23, \"foo\" );";
    assertEquals(expected, JavaScriptPrinter.printTokens(tokens));
  }
Exemple #4
0
  @Test
  public void testRemoveVariantConditionalWithElseBlock() throws Exception {
    String input =
        "if( rwt.util.Variant.isSet( \"qx.debug\", \"on\" ) ) {\n"
            + "  a = 1;\n"
            + "}\n else {\n"
            + "  b = 2;\n"
            + "}";
    TokenList tokens = TestUtil.parse(input);

    QxCodeCleaner cleaner = new QxCodeCleaner(tokens);
    cleaner.cleanupQxCode();

    assertEquals("b = 2;", JavaScriptPrinter.printTokens(tokens));
  }
Exemple #5
0
  @Test
  public void testRemoveVariantConditionalBetweenStatements() throws Exception {
    String input =
        "a = 1;\n"
            + "if( rwt.util.Variant.isSet( \"qx.debug\", \"on\" ) ) {\n"
            + "  if( false ) { throw \"ERROR\" }\n"
            + "}\n"
            + "b = 2;";
    TokenList tokens = TestUtil.parse(input);

    QxCodeCleaner cleaner = new QxCodeCleaner(tokens);
    cleaner.cleanupQxCode();

    assertEquals("a = 1;\nb = 2;", JavaScriptPrinter.printTokens(tokens));
  }
Exemple #6
0
  @Test
  public void testReplaceVariantSelection() throws Exception {
    String input =
        "result = rwt.util.Variant.select( \"qx.debug\", {\n"
            + "  \"on\": {\n"
            + "    \"foo\" : 23,\n"
            + "    \"bar\" : 42\n"
            + "  },\n"
            + "  \"default\" : null\n"
            + "} )";
    TokenList tokens = TestUtil.parse(input);

    QxCodeCleaner cleaner = new QxCodeCleaner(tokens);
    cleaner.cleanupQxCode();

    assertEquals("result = null;", JavaScriptPrinter.printTokens(tokens));
  }