110 |
109 |
111 public void elideStartUpFromSave() throws IOException { |
110 public void elideStartUpFromSave() throws IOException { |
112 Compiler compiler = new Compiler(); |
111 Compiler compiler = new Compiler(); |
113 Path path = compiler.getPath("myfile"); |
112 Path path = compiler.getPath("myfile"); |
114 test( |
113 test( |
115 (a) -> assertCommandCheckOutput(a, "123", |
114 (a) -> assertCommandOutputContains(a, "123", "type int"), |
116 (s) -> assertTrue(s.contains("type int"), s)), |
|
117 (a) -> assertCommand(a, "/save " + path.toString(), "") |
115 (a) -> assertCommand(a, "/save " + path.toString(), "") |
118 ); |
116 ); |
119 try (Stream<String> lines = Files.lines(path)) { |
117 try (Stream<String> lines = Files.lines(path)) { |
120 assertEquals(lines.count(), 1, "Expected only one saved line"); |
118 assertEquals(lines.count(), 1, "Expected only one saved line"); |
121 } |
119 } |
592 (a) -> assertVariable(a, "int", "a"), |
590 (a) -> assertVariable(a, "int", "a"), |
593 (a) -> assertVariable(a, "double", "b", "10", "10.0"), |
591 (a) -> assertVariable(a, "double", "b", "10", "10.0"), |
594 (a) -> assertMethod(a, "void f() {}", "()V", "f"), |
592 (a) -> assertMethod(a, "void f() {}", "()V", "f"), |
595 (a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"), |
593 (a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"), |
596 (a) -> assertCommand(a, "/save " + startUpFile.toString(), null), |
594 (a) -> assertCommand(a, "/save " + startUpFile.toString(), null), |
597 (a) -> assertCommand(a, "/setstart " + startUpFile.toString(), null) |
595 (a) -> assertCommand(a, "/set start " + startUpFile.toString(), null) |
598 ); |
596 ); |
599 Path unknown = compiler.getPath("UNKNOWN"); |
597 Path unknown = compiler.getPath("UNKNOWN"); |
600 test( |
598 test( |
601 (a) -> assertCommand(a, "/setstart " + unknown.toString(), |
599 (a) -> assertCommand(a, "/set start " + unknown.toString(), |
602 "| File '" + unknown + "' for /setstart is not found.\n") |
600 "| File '" + unknown + "' for /set start is not found.\n") |
603 ); |
601 ); |
604 test(false, new String[0], |
602 test(false, new String[0], |
605 (a) -> { |
603 (a) -> { |
606 loadVariable(a, "int", "a"); |
604 loadVariable(a, "int", "a"); |
607 loadVariable(a, "double", "b", "10.0", "10.0"); |
605 loadVariable(a, "double", "b", "10.0", "10.0"); |
634 public void testEmptyClassPath() { |
632 public void testEmptyClassPath() { |
635 test(after -> assertCommand(after, "/classpath", "| /classpath requires a path argument\n")); |
633 test(after -> assertCommand(after, "/classpath", "| /classpath requires a path argument\n")); |
636 } |
634 } |
637 |
635 |
638 public void testNoArgument() { |
636 public void testNoArgument() { |
639 String[] commands = {"/save", "/open", "/setstart"}; |
637 String[] commands = {"/save", "/open", "/set start"}; |
640 test(Stream.of(commands) |
638 test(Stream.of(commands) |
641 .map(cmd -> { |
639 .map(cmd -> { |
642 String c = cmd; |
640 String c = cmd; |
643 final String finalC = c; |
641 final String finalC = c; |
644 return (ReplTest) after -> assertCommand(after, cmd, |
642 return (ReplTest) after -> assertCommand(after, cmd, |
668 |
666 |
669 public void testRemoteExit() { |
667 public void testRemoteExit() { |
670 test( |
668 test( |
671 a -> assertVariable(a, "int", "x"), |
669 a -> assertVariable(a, "int", "x"), |
672 a -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
670 a -> assertCommandCheckOutput(a, "/vars", assertVariables()), |
673 a -> assertCommandCheckOutput(a, "System.exit(5);", s -> |
671 a -> assertCommandOutputContains(a, "System.exit(5);", "terminated"), |
674 assertTrue(s.contains("terminated"), s)), |
|
675 a -> assertCommandCheckOutput(a, "/vars", s -> |
672 a -> assertCommandCheckOutput(a, "/vars", s -> |
676 assertTrue(s.trim().isEmpty(), s)), |
673 assertTrue(s.trim().isEmpty(), s)), |
677 a -> assertMethod(a, "void f() { }", "()void", "f"), |
674 a -> assertMethod(a, "void f() { }", "()void", "f"), |
678 a -> assertCommandCheckOutput(a, "/methods", assertMethods()) |
675 a -> assertCommandCheckOutput(a, "/methods", assertMethods()) |
679 ); |
676 ); |
697 s -> checkLineToList(s, START_UP)), |
694 s -> checkLineToList(s, START_UP)), |
698 a -> assertCommandCheckOutput(a, "/list " + arg, |
695 a -> assertCommandCheckOutput(a, "/list " + arg, |
699 s -> assertEquals(s, "| No definition or id named " + arg + |
696 s -> assertEquals(s, "| No definition or id named " + arg + |
700 " found. There are no active definitions.\n")), |
697 " found. There are no active definitions.\n")), |
701 a -> assertVariable(a, "int", "aardvark"), |
698 a -> assertVariable(a, "int", "aardvark"), |
702 a -> assertCommandCheckOutput(a, "/list aardvark", |
699 a -> assertCommandOutputContains(a, "/list aardvark", "aardvark"), |
703 s -> assertTrue(s.contains("aardvark"))), |
|
704 a -> assertCommandCheckOutput(a, "/list start", |
700 a -> assertCommandCheckOutput(a, "/list start", |
705 s -> checkLineToList(s, START_UP)), |
701 s -> checkLineToList(s, START_UP)), |
706 a -> assertCommandCheckOutput(a, "/list all", |
702 a -> assertCommandCheckOutput(a, "/list all", |
707 s -> checkLineToList(s, startVarList)), |
703 s -> checkLineToList(s, startVarList)), |
708 a -> assertCommandCheckOutput(a, "/list printf", |
704 a -> assertCommandCheckOutput(a, "/list printf", |
712 " found. Try /list without arguments.\n")) |
708 " found. Try /list without arguments.\n")) |
713 ); |
709 ); |
714 } |
710 } |
715 |
711 |
716 public void testFeedbackNegative() { |
712 public void testFeedbackNegative() { |
717 test(a -> assertCommandCheckOutput(a, "/feedback aaaa", |
713 test(a -> assertCommandCheckOutput(a, "/set feedback aaaa", |
718 assertStartsWith("| Follow /feedback with of the following"))); |
714 assertStartsWith("| Does not match any current feedback mode"))); |
719 } |
715 } |
720 |
716 |
721 public void testFeedbackOff() { |
717 public void testFeedbackOff() { |
722 for (String off : new String[]{"o", "off"}) { |
718 for (String off : new String[]{"o", "off"}) { |
723 test( |
719 test( |
724 a -> assertCommand(a, "/feedback " + off, ""), |
720 a -> assertCommand(a, "/set feedback " + off, ""), |
725 a -> assertCommand(a, "int a", ""), |
721 a -> assertCommand(a, "int a", ""), |
726 a -> assertCommand(a, "void f() {}", ""), |
722 a -> assertCommand(a, "void f() {}", ""), |
727 a -> assertCommandCheckOutput(a, "aaaa", assertStartsWith("| Error:")), |
723 a -> assertCommandCheckOutput(a, "aaaa", assertStartsWith("| Error:")), |
728 a -> assertCommandCheckOutput(a, "public void f() {}", assertStartsWith("| Warning:")) |
724 a -> assertCommandCheckOutput(a, "public void f() {}", assertStartsWith("| Warning:")) |
729 ); |
|
730 } |
|
731 } |
|
732 |
|
733 public void testFeedbackConcise() { |
|
734 Compiler compiler = new Compiler(); |
|
735 Path testConciseFile = compiler.getPath("testConciseFeedback"); |
|
736 String[] sources = new String[] {"int a", "void f() {}", "class A {}", "a = 10"}; |
|
737 compiler.writeToFile(testConciseFile, sources); |
|
738 for (String concise : new String[]{"c", "concise"}) { |
|
739 test( |
|
740 a -> assertCommand(a, "/feedback " + concise, ""), |
|
741 a -> assertCommand(a, sources[0], ""), |
|
742 a -> assertCommand(a, sources[1], ""), |
|
743 a -> assertCommand(a, sources[2], ""), |
|
744 a -> assertCommand(a, sources[3], "| a : 10\n"), |
|
745 a -> assertCommand(a, "/o " + testConciseFile.toString(), "| a : 10\n") |
|
746 ); |
725 ); |
747 } |
726 } |
748 } |
727 } |
749 |
728 |
750 public void testFeedbackNormal() { |
729 public void testFeedbackNormal() { |
757 "| Added method f()\n", |
736 "| Added method f()\n", |
758 "| Added class A\n", |
737 "| Added class A\n", |
759 "| Variable a has been assigned the value 10\n" |
738 "| Variable a has been assigned the value 10\n" |
760 }; |
739 }; |
761 compiler.writeToFile(testNormalFile, sources2); |
740 compiler.writeToFile(testNormalFile, sources2); |
762 for (String feedback : new String[]{"/f", "/feedback"}) { |
741 for (String feedback : new String[]{"/set f", "/set feedback"}) { |
763 for (String feedbackState : new String[]{"n", "normal", "v", "verbose"}) { |
742 for (String feedbackState : new String[]{"n", "normal", "o", "off"}) { |
764 String f = null; |
|
765 if (feedbackState.startsWith("n")) { |
|
766 f = "normal"; |
|
767 } else if (feedbackState.startsWith("v")) { |
|
768 f = "verbose"; |
|
769 } |
|
770 final String finalF = f; |
|
771 test( |
743 test( |
772 a -> assertCommand(a, feedback + " " + feedbackState, "| Feedback mode: " + finalF +"\n"), |
744 a -> assertCommand(a, feedback + " " + feedbackState, "| Feedback mode: normal\n"), |
773 a -> assertCommand(a, sources[0], output[0]), |
745 a -> assertCommand(a, sources[0], output[0]), |
774 a -> assertCommand(a, sources[1], output[1]), |
746 a -> assertCommand(a, sources[1], output[1]), |
775 a -> assertCommand(a, sources[2], output[2]), |
747 a -> assertCommand(a, sources[2], output[2]), |
776 a -> assertCommand(a, sources[3], output[3]), |
748 a -> assertCommand(a, sources[3], output[3]), |
777 a -> assertCommand(a, "/o " + testNormalFile.toString(), |
749 a -> assertCommand(a, "/o " + testNormalFile.toString(), "") |
778 "| Modified variable a of type int\n" + |
|
779 "| Modified method f()\n" + |
|
780 "| Update overwrote method f()\n" + |
|
781 "| Modified class A\n" + |
|
782 "| Update overwrote class A\n" + |
|
783 "| Variable a has been assigned the value 10\n") |
|
784 ); |
750 ); |
785 } |
751 } |
786 } |
|
787 } |
|
788 |
|
789 public void testFeedbackDefault() { |
|
790 Compiler compiler = new Compiler(); |
|
791 Path testDefaultFile = compiler.getPath("testDefaultFeedback"); |
|
792 String[] sources = new String[] {"int a", "void f() {}", "class A {}", "a = 10"}; |
|
793 String[] output = new String[] { |
|
794 "| Added variable a of type int\n", |
|
795 "| Added method f()\n", |
|
796 "| Added class A\n", |
|
797 "| Variable a has been assigned the value 10\n" |
|
798 }; |
|
799 compiler.writeToFile(testDefaultFile, sources); |
|
800 for (String defaultFeedback : new String[]{"", "d", "default"}) { |
|
801 test( |
|
802 a -> assertCommand(a, "/feedback o", ""), |
|
803 a -> assertCommand(a, "int x", ""), |
|
804 a -> assertCommand(a, "/feedback " + defaultFeedback, "| Feedback mode: default\n"), |
|
805 a -> assertCommand(a, sources[0], output[0]), |
|
806 a -> assertCommand(a, sources[1], output[1]), |
|
807 a -> assertCommand(a, sources[2], output[2]), |
|
808 a -> assertCommand(a, sources[3], output[3]), |
|
809 a -> assertCommand(a, "/o " + testDefaultFile.toString(), "") |
|
810 ); |
|
811 } |
752 } |
812 } |
753 } |
813 |
754 |
814 public void testDrop() { |
755 public void testDrop() { |
815 test(false, new String[]{"-nostartup"}, |
756 test(false, new String[]{"-nostartup"}, |
904 } |
845 } |
905 } |
846 } |
906 |
847 |
907 public void testCommandPrefix() { |
848 public void testCommandPrefix() { |
908 test(a -> assertCommandCheckOutput(a, "/s", |
849 test(a -> assertCommandCheckOutput(a, "/s", |
909 assertStartsWith("| Command: /s is ambiguous: /seteditor, /save, /setstart")), |
850 assertStartsWith("| Command: /s is ambiguous: /save, /set")), |
910 a -> assertCommand(a, "int var", "| Added variable var of type int\n"), |
851 a -> assertCommand(a, "int var", "| Added variable var of type int\n"), |
911 a -> assertCommandCheckOutput(a, "/va", |
852 a -> assertCommandCheckOutput(a, "/va", |
912 assertStartsWith("| int var = 0")), |
853 assertStartsWith("| int var = 0")), |
913 a -> assertCommandCheckOutput(a, "/save", |
854 a -> assertCommandCheckOutput(a, "/save", |
914 assertStartsWith("| The /save command requires a filename argument."))); |
855 assertStartsWith("| The /save command requires a filename argument."))); |