Example #1
0
  public void testPastePostStringAdaptiveIndent() throws BadLocationException {
    AutoEditTester tester = UiReleaseTests.createAutoEditTester();
    String content =
        "class foobar;\n"
            + "\n"
            + "function void foo2();\n"
            + "	$psprintf(\"Hello World\\n    Testing %d\\n\",\n"
            + "		a, b, c);\n\n";
    String expected =
        "class foobar;\n"
            + "\n"
            + "function void foo2();\n"
            + "	$psprintf(\"Hello World\\n    Testing %d\\n\",\n"
            + "		a, b, c);\n"
            + ""
            + "	if (foobar) begin\n"
            + "		a = 6;\n"
            + "	end\n";
    tester.setContent(content);
    // SVCorePlugin.getDefault().enableDebug(false);
    tester.paste("if (foobar) begin\n" + "a = 6;\n" + "end\n");

    String result = tester.getContent();

    fLog.debug("Result:\n" + result);
    IndentComparator.compare("testPastePostStringAdaptiveIndent", expected, result);
  }
Example #2
0
  public void testPaste() throws BadLocationException {
    String first =
        "`ifndef INCLUDED_transport_packet_svh\n"
            + "`define INCLUDED_transport_packet_svh\n"
            + "\n";

    String text = "class vmm_xactor;\n" + "\n" + "`VMM_NOTIFY notify;\n";

    String expected =
        "`ifndef INCLUDED_transport_packet_svh\n"
            + "`define INCLUDED_transport_packet_svh\n"
            + "\n"
            + "class vmm_xactor;\n"
            + "\n"
            + "	`VMM_NOTIFY notify;\n";

    AutoEditTester tester = UiReleaseTests.createAutoEditTester();
    tester.type(first);
    tester.paste(text);

    String content = tester.getContent();

    fLog.debug("Result:\n" + content);
    IndentComparator.compare("testPaste", expected, content);
  }
Example #3
0
  public void testAutoPostSingleComment() throws BadLocationException {
    String content =
        "class foo;\n"
            + "function void my_func();\n"
            + "if (foobar) begin\n"
            + "end else begin\n"
            + "// comment block\n"
            + "a.b = 5;\n"
            + "end\n"
            + "endfunction\n"
            + "endclass\n";
    String expected =
        "class foo;\n"
            + "	function void my_func();\n"
            + "		if (foobar) begin\n"
            + "		end else begin\n"
            + "			// comment block\n"
            + "			a.b = 5;\n"
            + "		end\n"
            + "	endfunction\n"
            + "endclass\n";

    AutoEditTester tester = UiReleaseTests.createAutoEditTester();
    tester.type(content);
    tester.paste(content);

    String result = tester.getContent();

    fLog.debug("Result:\n" + result);
    IndentComparator.compare("testAutoPostSingleComment", expected + expected, result);
  }
Example #4
0
  public void testPasteModule() throws BadLocationException {
    String first = "module t();\n" + "logic a;\n" + "endmodule\n";

    String text = "\n" + "	logic a;\n";
    String expected = "module t();\n" + "	logic a;\n" + "endmodule\n";
    String expected_text = "	logic a;\n";

    AutoEditTester tester = UiReleaseTests.createAutoEditTester();
    tester.type(first);
    tester.paste(first); // Paste to make sure we get an identical result to when we type stuff
    tester.setCaretOffset(first.length() * 2 + 1);
    tester.paste(text);

    String content = tester.getContent();

    fLog.debug("content=\"" + content + "\"");
    IndentComparator.compare("testPasteModule", expected + expected + expected_text, content);
  }
Example #5
0
  public void testAutoIndentAlways() throws BadLocationException {
    AutoEditTester tester = UiReleaseTests.createAutoEditTester();
    String content =
        "module foo;\n"
            + "always @(posedge clk) begin\n"
            + "if (~rst_n_clk) bus_release_cnt <= 'b0;\n"
            + "else if (slow_packet_finished) bus_release_cnt <= bus_release_cnt + 1'b1;\n"
            + "else if (|bus_release_cnt) bus_release_cnt <= bus_release_cnt + 1'b1;\n"
            + "else if(jill) bus_release_cnt <= bus_release_cnt + 1'b1;\n"
            + "end\n"
            + "always @(posedge clk)\n"
            + "begin\n"
            + "if (~rst_n_clk) bus_release_cnt <= 'b0;\n"
            + "else if (slow_packet_finished) bus_release_cnt <= bus_release_cnt + 1'b1;\n"
            + "else if (|bus_release_cnt) bus_release_cnt <= bus_release_cnt + 1'b1;\n"
            + "else if(jill) bus_release_cnt <= bus_release_cnt + 1'b1;\n"
            + "end\n"
            + "always @(posedge clk)\n"
            + "if (~rst_n_clk) bus_release_cnt <= 'b0;\n"
            + "else if (slow_packet_finished) bus_release_cnt <= bus_release_cnt + 1'b1;\n"
            + "else if (|bus_release_cnt) bus_release_cnt <= bus_release_cnt + 1'b1;\n"
            + "else if(jill) bus_release_cnt <= bus_release_cnt + 1'b1;\n"
            + "endmodule\n";
    // Type & then paste, to make sure that what we type, and what we get are identical!
    tester.type(content);
    tester.paste(content);

    String result = tester.getContent();

    String expected =
        "module foo;\n"
            + "	always @(posedge clk) begin\n"
            + "		if (~rst_n_clk) bus_release_cnt <= 'b0;\n"
            + "		else if (slow_packet_finished) bus_release_cnt <= bus_release_cnt + 1'b1;\n"
            + "		else if (|bus_release_cnt) bus_release_cnt <= bus_release_cnt + 1'b1;\n"
            + "		else if(jill) bus_release_cnt <= bus_release_cnt + 1'b1;\n"
            + "	end\n"
            + "	always @(posedge clk)\n"
            + "	begin\n"
            + "		if (~rst_n_clk) bus_release_cnt <= 'b0;\n"
            + "		else if (slow_packet_finished) bus_release_cnt <= bus_release_cnt + 1'b1;\n"
            + "		else if (|bus_release_cnt) bus_release_cnt <= bus_release_cnt + 1'b1;\n"
            + "		else if(jill) bus_release_cnt <= bus_release_cnt + 1'b1;\n"
            + "	end\n"
            + "	always @(posedge clk)\n"
            + "		if (~rst_n_clk) bus_release_cnt <= 'b0;\n"
            + "		else if (slow_packet_finished) bus_release_cnt <= bus_release_cnt + 1'b1;\n"
            + "		else if (|bus_release_cnt) bus_release_cnt <= bus_release_cnt + 1'b1;\n"
            + "		else if(jill) bus_release_cnt <= bus_release_cnt + 1'b1;\n"
            + "endmodule\n";

    fLog.debug("Result:\n" + result);
    // Note that we are expecting expected twice, proving that the formatting when we type, is
    // identical
    // to the result when we paste
    IndentComparator.compare("testAutoIndentAlways", expected + expected, result);
  }
Example #6
0
  // This test checks constraints
  public void testIndentConstraint() throws BadLocationException {
    //	String input =
    //			"class someclass;\n" +
    //			"constraint clock {\n" +
    //			"clk_cfg.period dist {\n" +
    //			"[1:10  ] :/ 1,\n" +
    //			"11       := 1,\n" +
    //			"12       := 1,\n" +
    //			"[13: 15] :/ 1\n" +
    //			"};\n" +
    //			"clk_cfg.jitter < (3 * 1000);\n" +
    //			"}\n" +
    //			"function void my_func;\n" +
    //			"my_class cls1; \n" +
    //			"assert(cls1.randomize() with {\n" +
    //			"cls1.a == 2;\n" +
    //			"})\n" +
    //			"else $display (\"ERROR\");\n" +
    //			"endfunction\n" +
    //			"endclass\n"
    //			;

    String expected =
        "class someclass;\n"
            + "	constraint clock {\n"
            + "		clk_cfg.period dist {\n"
            + "			[1:10  ] :/ 1,\n"
            + "			11       := 1,\n"
            + "			12       := 1,\n"
            + "			[13: 15] :/ 1\n"
            + "		};\n"
            + "		clk_cfg.jitter < (3 * 1000);\n"
            + "	}\n"
            + "	function void my_func;\n"
            + "		my_class cls1; \n"
            + "		assert(cls1.randomize() with {\n"
            + "				cls1.a == 2;\n"
            + "				})\n"
            + "		else $display (\"ERROR\");\n"
            + "	endfunction\n"
            + "endclass\n";

    String input = IndentTests.removeLeadingWS(expected).toString();

    AutoEditTester tester = UiReleaseTests.createAutoEditTester();
    tester.type(input);
    String result_type = tester.getContent();

    IndentComparator.compare("testIndentConstraint - type", expected, result_type);
    tester.paste(input);
    String result_paste = tester.getContent();

    SVCorePlugin.getDefault().enableDebug(false);

    IndentComparator.compare("testIndentConstraint - paste", expected, result_paste);
  }
Example #7
0
  public void testGenerateFor() throws BadLocationException {
    AutoEditTester tester = UiReleaseTests.createAutoEditTester();
    String content =
        "module foo;\n"
            + "generate begin : named_gen\n"
            + "for (i=0; i<5; i++)\n"
            + "begin : named_for\n"
            + "submod sm ();\n"
            + "end\n"
            + "end\n"
            + "endgenerate\n"
            + "generate begin : named_gen\n"
            + "for (i=0; i<5; i++)\n"
            + "begin : named_for\n"
            + "submod sm ();\n"
            + "end\n"
            + "end\n"
            + "endgenerate\n"
            + "endmodule\n";
    // Type & then paste, to make sure that what we type, and what we get are identical!
    tester.type(content);
    tester.paste(content);

    String result = tester.getContent();

    String expected =
        "module foo;\n"
            + "	generate begin : named_gen\n"
            + "		for (i=0; i<5; i++)\n"
            + "		begin : named_for\n"
            + "			submod sm ();\n"
            + "		end\n"
            + "	end\n"
            + "	endgenerate\n"
            + "	generate begin : named_gen\n"
            + "		for (i=0; i<5; i++)\n"
            + "		begin : named_for\n"
            + "			submod sm ();\n"
            + "		end\n"
            + "	end\n"
            + "	endgenerate\n"
            + "endmodule\n";

    fLog.debug("Result:\n" + result);
    // Note that we are expecting expected twice, proving that the formatting when we type, is
    // identical
    // to the result when we paste
    IndentComparator.compare("testGenerateFor", expected + expected, result);
  }
Example #8
0
  public void testModuleWires() throws BadLocationException {
    String content = "module t();\n" + "logic a;\n" + "logic b;\n" + "endmodule\n";

    String expected = "module t();\n" + "	logic a;\n" + "	logic b;\n" + "endmodule\n";

    AutoEditTester tester = UiReleaseTests.createAutoEditTester();
    tester.type(content);
    tester.paste(
        content); // make sure that if we paste the same code, that we get the same if we had typed
    // it

    String result = tester.getContent();

    fLog.debug("Result:\n" + result);
    IndentComparator.compare("testModuleWires", expected + expected, result);
  }
Example #9
0
  public void testPasteAlwaysComb() throws BadLocationException {
    String content =
        "module t;\n"
            + "logic a;\n"
            + "\n"
            + "always_comb begin\n"
            + "a = 0;\n"
            + "end\n"
            + "endmodule\n";
    String paste = "always_comb begin\n" + "		a = 0;\n" + "	end";

    AutoEditTester tester = UiReleaseTests.createAutoEditTester();
    tester.type(content);
    String result;
    result = tester.getContent();

    // Check the initial result
    IndentComparator.compare(
        "testPasteAlwaysComb",
        "module t;\n"
            + "	logic a;\n"
            + "\n"
            + "	always_comb begin\n"
            + "		a = 0;\n"
            + "	end\n"
            + "endmodule\n",
        result);

    tester.setCaretOffset(("module t;\n" + "	logic a;\n").length() + 1);

    tester.paste(paste);
    result = tester.getContent();

    fLog.debug("result=\"" + result + "\"");
    IndentComparator.compare(
        "testPasteAlwaysComb",
        "module t;\n"
            + "	logic a;\n"
            + "	always_comb begin\n"
            + "		a = 0;\n"
            + "	end\n"
            + "	always_comb begin\n"
            + "		a = 0;\n"
            + "	end\n"
            + "endmodule\n",
        result);
  }
Example #10
0
  public void testPasteInsertOpeningComment() throws BadLocationException {
    String input =
        "class foo;\n"
            + "\n"
            + "	function void foobar;\n"
            + "		int var;\n"
            + "		var = 5;\n"
            + "		bar = 6;\n"
            + "		*/\n"
            + "	endfunction\n"
            + "\n"
            + "endclass\n";
    String expected =
        "class foo;\n"
            + "\n"
            + "	function void foobar;\n"
            + "		int var;\n"
            + "/*\n"
            + "		var = 5;\n"
            + "		bar = 6;\n"
            + "		*/\n"
            + "	endfunction\n"
            + "\n"
            + "endclass\n";

    AutoEditTester tester = UiReleaseTests.createAutoEditTester();
    tester.setContent(input);

    tester.setCaretOffset(0);
    while (true) {
      String line = tester.readLine();
      fLog.debug("line=\"" + line + "\"");

      if (line.trim().startsWith("int var")) {
        break;
      }
    }
    tester.paste("/*\n");

    String result = tester.getContent();
    fLog.debug("Result:\n" + result);
    IndentComparator.compare("testPasteInsertOpeningComment", expected, result);
  }
Example #11
0
  public void testPasteAdaptiveIndent() throws BadLocationException {
    AutoEditTester tester = UiReleaseTests.createAutoEditTester();
    String content = "class foobar;\n" + "\n" + "function void foo2();\n\n";
    String expected =
        "class foobar;\n"
            + "\n"
            + "function void foo2();\n"
            + "	if (foobar) begin\n"
            + "		a = 6;\n"
            + "	end\n";

    tester.setContent(content);
    tester.paste("if (foobar) begin\n" + "a = 6;\n" + "end\n");

    String result = tester.getContent();

    fLog.debug("Result:\n" + result);
    IndentComparator.compare("testPasteAdaptiveIndent", expected, result);
  }
Example #12
0
  public void testPasteInModule() throws BadLocationException {

    SVCorePlugin.getDefault().enableDebug(false);

    String first = "module t();\n" + "	logic a;\n" + "endmodule\n";

    String text = "logic b;\n";

    String expected = "module t();\n" + "	logic a;\n" + "	logic b;\n" + "endmodule\n";

    AutoEditTester tester = UiReleaseTests.createAutoEditTester();
    tester.setContent(first);
    //		tester.type(first);
    tester.setCaretOffset(("module t();\n" + "	logic a;\n").length());

    tester.paste(text);

    String content = tester.getContent();

    fLog.debug("Result:\n" + content);
    IndentComparator.compare("", expected, content);
  }
Example #13
0
  public void testModuleWiresPastePost() throws BadLocationException {
    String content = "module t();\n" + "logic a;\n" + "logic b;\n" + "endmodule\n";

    String expected =
        "module t();\n"
            + "	logic a;\n"
            + "	logic b;\n"
            + "endmodule\n"
            + "module b();\n"
            + "	logic a;\n"
            + "	logic b;\n"
            + "endmodule\n";

    AutoEditTester tester = UiReleaseTests.createAutoEditTester();
    tester.type(content);
    tester.paste("module b();\n" + "logic a;\n" + "logic b;\n" + "endmodule\n");

    String result = tester.getContent();

    fLog.debug("Result:\n" + result);
    IndentComparator.compare("testModuleWires", expected, result);
  }
Example #14
0
  public void testAutoIndentFor() throws BadLocationException {

    SVCorePlugin.getDefault().enableDebug(false);

    String content =
        "module t();\n"
            + "initial\n"
            + "begin\n"
            + "for (i=0; i<10; i++) begin : some_label\n"
            + "for (j=0; j<10; j++)\n"
            + "begin : some_label2\n"
            + "foo = bar;\n"
            + "end\n"
            + "end\n"
            + "end\n"
            + "endmodule\n";
    String expected =
        "module t();\n"
            + "	initial\n"
            + "	begin\n"
            + "		for (i=0; i<10; i++) begin : some_label\n"
            + "			for (j=0; j<10; j++)\n"
            + "			begin : some_label2\n"
            + "				foo = bar;\n"
            + "			end\n"
            + "		end\n"
            + "	end\n"
            + "endmodule\n";

    AutoEditTester tester = UiReleaseTests.createAutoEditTester();
    tester.type(content);
    tester.paste(content); // make sure that paste parses the same as typing

    String result = tester.getContent();

    fLog.debug("Result:\n" + content);
    IndentComparator.compare("", expected + expected, result);
  }
Example #15
0
  public void testPasteModuleNoCR() throws BadLocationException {

    SVCorePlugin.getDefault().enableDebug(false);

    String first =
        "module t;\n"
            + "	logic a;\n"
            + "	always_comb begin\n"
            + "		a = 0;\n"
            + "	end\n"
            + "endmodule";

    AutoEditTester tester = UiReleaseTests.createAutoEditTester();
    tester.paste(first);

    first += "\n";

    String content = tester.getContent();

    fLog.debug("Result:\n" + content);
    fLog.debug("Expected:\n" + first);
    IndentComparator.compare("testPasteModuleNoCR", first, content);
  }
Example #16
0
  // This test multi-line statements
  public void testMultiLineStatements() throws BadLocationException {
    String input =
        "program some_pgm;\n"
            + "always @*\n"
            + "begin\n"
            + "jane = bob +\n"
            + "other;\n"
            + "jane = thing + thong;\n"
            + "asdf = 1 + 2;\n"
            + "if ((a ||b) &&\n"
            + "c)\n"
            + "begin\n"
            + "jane = bob +\n"
            + "other;\n"
            + "end\n"
            + "if (\n"
            + "(a > b ()) ||\n"
            + "(b)\n"
            + ")\n"
            + "thing = 1;\n"
            + "else if (\n"
            + "(\n"
            + "c ||\n"
            + "d\n"
            + ")\n"
            + ")\n"
            + "thing2 = 1;\n"
            + "end\n"
            + "assign jane = bob +\n"
            + "other;\n"
            + "endprogram\n";

    String expected =
        "program some_pgm;\n"
            + "	always @*\n"
            + "	begin\n"
            + "		jane = bob +\n"
            + "			other;\n"
            + "		jane = thing + thong;\n"
            + "		asdf = 1 + 2;\n"
            + "		if ((a ||b) &&\n"
            + "				c)\n"
            + "		begin\n"
            + "			jane = bob +\n"
            + "				other;\n"
            + "		end\n"
            + "		if (\n"
            + "				(a > b ()) ||\n"
            + "				(b)\n"
            + "			)\n"
            + "			thing = 1;\n"
            + "		else if (\n"
            + "				(\n"
            + "					c ||\n"
            + "					d\n"
            + "				)\n"
            + "			)\n"
            + "			thing2 = 1;\n"
            + "	end\n"
            + "	assign jane = bob +\n"
            + "		other;\n"
            + "endprogram\n";

    AutoEditTester tester = UiReleaseTests.createAutoEditTester();
    tester.paste(input);
    String result = tester.getContent();

    IndentComparator.compare("testMultiLineStatements", expected, result);
  }