diff --git a/tests/find_files/re_greedy_False_0_True.html b/tests/find_files/re_greedy_False_0_True.html new file mode 100644 index 00000000..6e875a47 --- /dev/null +++ b/tests/find_files/re_greedy_False_0_True.html @@ -0,0 +1,18 @@ + + +

>>>

+

Find in workboxs: "search.+term" (regex)

+


+

# File: First Group/First Tab

+

1: Search term

+

3: search term

+

6: search term at the start of the line

+

11: search is in this line but the actual search term is in the middle

+

17: This line has underscores around _search term_ and "search term" as double quotes

+

18: This line has the search term in multple times... search term

+

19: Search term the search term with the search term

+


+

7 matches in 1 workboxes

+


diff --git a/tests/find_files/re_greedy_False_2_True.html b/tests/find_files/re_greedy_False_2_True.html new file mode 100644 index 00000000..74b28163 --- /dev/null +++ b/tests/find_files/re_greedy_False_2_True.html @@ -0,0 +1,32 @@ + + +

>>>

+

Find in workboxs: "search.+term" (regex)

+


+

# File: First Group/First Tab

+

1: Search term

+

2 line 2

+

3: search term

+

4

+

5 line 5

+

6: search term at the start of the line

+

7 line 7

+

8 line 8

+

..

+

9: line 9

+

10 line 10

+

11 search is in this line but the actual search term is in the middle

+

12

+

13

+

..

+

15: line 15

+

16

+

17 This line has underscores around _search term_ and "search term" as double quotes

+

18: This line has the search term in multple times... search term

+

19: Search term the search term with the search term

+

20 The "newline at end of file" is not printed due to str.splitlines.

+


+

7 matches in 1 workboxes

+


diff --git a/tests/find_files/re_simple_False_0_True.html b/tests/find_files/re_simple_False_0_True.html new file mode 100644 index 00000000..0a0cc40d --- /dev/null +++ b/tests/find_files/re_simple_False_0_True.html @@ -0,0 +1,18 @@ + + +

>>>

+

Find in workboxs: "search term" (regex)

+


+

# File: First Group/First Tab

+

1: Search term

+

3: search term

+

6: search term at the start of the line

+

11: search is in this line but the actual search term is in the middle

+

17: This line has underscores around _search term_ and "search term" as double quotes

+

18: This line has the search term in multple times... search term

+

19: Search term the search term with the search term

+


+

11 matches in 1 workboxes

+


diff --git a/tests/find_files/re_simple_False_2_True.html b/tests/find_files/re_simple_False_2_True.html new file mode 100644 index 00000000..c4602843 --- /dev/null +++ b/tests/find_files/re_simple_False_2_True.html @@ -0,0 +1,32 @@ + + +

>>>

+

Find in workboxs: "search term" (regex)

+


+

# File: First Group/First Tab

+

1: Search term

+

2 line 2

+

3: search term

+

4

+

5 line 5

+

6: search term at the start of the line

+

7 line 7

+

8 line 8

+

..

+

9: line 9

+

10 line 10

+

11 search is in this line but the actual search term is in the middle

+

12

+

13

+

..

+

15: line 15

+

16

+

17 This line has underscores around _search term_ and "search term" as double quotes

+

18: This line has the search term in multple times... search term

+

19: Search term the search term with the search term

+

20 The "newline at end of file" is not printed due to str.splitlines.

+


+

11 matches in 1 workboxes

+


diff --git a/tests/find_files/re_simple_False_3_True.html b/tests/find_files/re_simple_False_3_True.html new file mode 100644 index 00000000..219d8559 --- /dev/null +++ b/tests/find_files/re_simple_False_3_True.html @@ -0,0 +1,33 @@ + + +

>>>

+

Find in workboxs: "search term" (regex)

+


+

# File: First Group/First Tab

+

1: Search term

+

2 line 2

+

3: search term

+

4

+

5 line 5

+

6: search term at the start of the line

+

7 line 7

+

8 line 8

+

9 line 9

+

..

+

10: line 10

+

11 search is in this line but the actual search term is in the middle

+

12

+

13

+

14 line 14

+

..

+

15: line 15

+

16

+

17 This line has underscores around _search term_ and "search term" as double quotes

+

18: This line has the search term in multple times... search term

+

19: Search term the search term with the search term

+

20 The "newline at end of file" is not printed due to str.splitlines.

+


+

11 matches in 1 workboxes

+


diff --git a/tests/find_files/re_simple_True_2_True.html b/tests/find_files/re_simple_True_2_True.html new file mode 100644 index 00000000..98cad733 --- /dev/null +++ b/tests/find_files/re_simple_True_2_True.html @@ -0,0 +1,32 @@ + + +

>>>

+

Find in workboxs: "search term" (regex, case sensitive)

+


+

# File: First Group/First Tab

+

1: Search term

+

2 line 2

+

3 search term

+

4

+

5 line 5

+

6: search term at the start of the line

+

7 line 7

+

8 line 8

+

..

+

9: line 9

+

10 line 10

+

11 search is in this line but the actual search term is in the middle

+

12

+

13

+

..

+

15: line 15

+

16

+

17 This line has underscores around _search term_ and "search term" as double quotes

+

18: This line has the search term in multple times... search term

+

19: Search term the search term with the search term

+

20 The "newline at end of file" is not printed due to str.splitlines.

+


+

9 matches in 1 workboxes

+


diff --git a/tests/find_files/simple_False_0_False.html b/tests/find_files/simple_False_0_False.html new file mode 100644 index 00000000..7cec69ee --- /dev/null +++ b/tests/find_files/simple_False_0_False.html @@ -0,0 +1,18 @@ + + +

>>>

+

Find in workboxs: "search term"

+


+

# File: First Group/First Tab

+

1: Search term

+

3: search term

+

6: search term at the start of the line

+

11: search is in this line but the actual search term is in the middle

+

17: This line has underscores around _search term_ and "search term" as double quotes

+

18: This line has the search term in multple times... search term

+

19: Search term the search term with the search term

+


+

11 matches in 1 workboxes

+


diff --git a/tests/find_files/simple_False_2_False.html b/tests/find_files/simple_False_2_False.html new file mode 100644 index 00000000..e749842e --- /dev/null +++ b/tests/find_files/simple_False_2_False.html @@ -0,0 +1,32 @@ + + +

>>>

+

Find in workboxs: "search term"

+


+

# File: First Group/First Tab

+

1: Search term

+

2 line 2

+

3: search term

+

4

+

5 line 5

+

6: search term at the start of the line

+

7 line 7

+

8 line 8

+

..

+

9 line 9

+

10 line 10

+

11: search is in this line but the actual search term is in the middle

+

12

+

13

+

..

+

15 line 15

+

16

+

17: This line has underscores around _search term_ and "search term" as double quotes

+

18: This line has the search term in multple times... search term

+

19: Search term the search term with the search term

+

20 The "newline at end of file" is not printed due to str.splitlines.

+


+

11 matches in 1 workboxes

+


diff --git a/tests/find_files/simple_False_3_False.html b/tests/find_files/simple_False_3_False.html new file mode 100644 index 00000000..7d944b70 --- /dev/null +++ b/tests/find_files/simple_False_3_False.html @@ -0,0 +1,33 @@ + + +

>>>

+

Find in workboxs: "search term"

+


+

# File: First Group/First Tab

+

1: Search term

+

2 line 2

+

3: search term

+

4

+

5 line 5

+

6: search term at the start of the line

+

7 line 7

+

8 line 8

+

9 line 9

+

..

+

10 line 10

+

11: search is in this line but the actual search term is in the middle

+

12

+

13

+

14 line 14

+

..

+

15 line 15

+

16

+

17: This line has underscores around _search term_ and "search term" as double quotes

+

18: This line has the search term in multple times... search term

+

19: Search term the search term with the search term

+

20 The "newline at end of file" is not printed due to str.splitlines.

+


+

11 matches in 1 workboxes

+


diff --git a/tests/find_files/simple_True_2_False.html b/tests/find_files/simple_True_2_False.html new file mode 100644 index 00000000..cbafe550 --- /dev/null +++ b/tests/find_files/simple_True_2_False.html @@ -0,0 +1,32 @@ + + +

>>>

+

Find in workboxs: "search term" (case sensitive)

+


+

# File: First Group/First Tab

+

1 Search term

+

2 line 2

+

3: search term

+

4

+

5 line 5

+

6: search term at the start of the line

+

7 line 7

+

8 line 8

+

..

+

9 line 9

+

10 line 10

+

11: search is in this line but the actual search term is in the middle

+

12

+

13

+

..

+

15 line 15

+

16

+

17: This line has underscores around _search term_ and "search term" as double quotes

+

18: This line has the search term in multple times... search term

+

19: Search term the search term with the search term

+

20 The "newline at end of file" is not printed due to str.splitlines.

+


+

9 matches in 1 workboxes

+


diff --git a/tests/find_files/tab_text.txt b/tests/find_files/tab_text.txt new file mode 100644 index 00000000..f84721f3 --- /dev/null +++ b/tests/find_files/tab_text.txt @@ -0,0 +1,20 @@ +Search term +line 2 +search term + +line 5 +search term at the start of the line +line 7 +line 8 +line 9 +line 10 +search is in this line but the actual search term is in the middle + + +line 14 +line 15 + +This line has underscores around _search term_ and "search term" as double quotes +This line has the search term in multple times... search term +Search term the search term with the search term +The "newline at end of file" is not printed due to str.splitlines. diff --git a/tests/find_files/test_find_files.py b/tests/find_files/test_find_files.py new file mode 100644 index 00000000..d70f9d4d --- /dev/null +++ b/tests/find_files/test_find_files.py @@ -0,0 +1,65 @@ +import os + +import pytest +from Qt.QtWidgets import QWidget + +import preditor +from preditor.gui.app import App +from preditor.gui.loggerwindow import LoggerWindow + +preditor.configure(name="pytest", streams=False) +app = App() +_root_window = QWidget() + + +def plog_instance(): + return LoggerWindow(parent=_root_window, prefs_enabled=False) + + +def text_for_test(filename): + dirname = os.path.dirname(__file__) + filename = os.path.join(dirname, filename) + with open(filename) as fle: + return fle.read() + + +@pytest.mark.parametrize( + "check_type,search_text,is_cs,context,is_re", + ( + # TODO: If the distance between two matches is exactly 2 * context, then + # dots are printed even though they should not be. Figure out a fix + # Simple search testing context and case + ("simple", "search term", False, 0, False), + ("simple", "search term", False, 2, False), + ("simple", "search term", False, 3, False), + ("simple", "search term", True, 2, False), + # Regex search testing context and case + ("re_simple", "search term", False, 0, True), + ("re_simple", "search term", False, 2, True), # TODO: Incorrect + ("re_simple", "search term", False, 3, True), # TODO: Incorrect + ("re_simple", "search term", True, 2, True), # TODO: Incorrect + # Complex regex + ("re_greedy", "search.+term", False, 0, True), + ("re_greedy", "search.+term", False, 2, True), # TODO: Incorrect + ), +) +def test_find_files(check_type, search_text, is_cs, context, is_re): + # NOTE: To generate html files add the text + plog = plog_instance() + _, workbox = plog.uiWorkboxTAB.add_new_tab("First Group", "First Tab") + check = text_for_test("{}_{}_{}_{}.html".format(check_type, is_cs, context, is_re)) + workbox.__set_text__(text_for_test("tab_text.txt")) + # Ensure the console is cleared + plog.clearLog() + + plog.uiFindInWorkboxesWGT.uiCaseSensitiveBTN.setChecked(is_cs) + plog.uiFindInWorkboxesWGT.uiContextSPN.setValue(context) + plog.uiFindInWorkboxesWGT.uiRegexBTN.setChecked(is_re) + plog.uiFindInWorkboxesWGT.uiFindTXT.setText(search_text) + + plog.uiFindInWorkboxesWGT.find() + text = plog.uiConsoleTXT.toHtml() + # To update tests, print text and save over top of the html. Then verify + # in a web browser that the html is rendered properly + print(text) + assert text == check.rstrip()