from queue import Queue

from lexos.processors.prepare.cutter import split_keep_whitespace, \
    count_words, strip_leading_white_space, strip_leading_blank_lines, \
    strip_leading_characters, strip_leading_words, strip_leading_lines


class TestBasicFunctions:
    def test_whitespace_split(self):
        assert split_keep_whitespace("the   string") == [
            "the", " ", "", " ", "", " ", "string"]

    def test_words_count(self):
        assert count_words([" "]) == 0
        assert count_words(["how", " ", "many", " ", "words"]) == 3

    def test_strip_leading_white_space(self):
        list_text_lead_white = [" ", "test", "   ", "line"]
        test_queue_ws = Queue()

        # putting all the words into test_queue
        for word in list_text_lead_white:
            test_queue_ws.put(word)

        # execute function with the created queue
        strip_leading_white_space(test_queue_ws)

        # convert back the queue into list and make assertion
        assert list(test_queue_ws.queue) == ["test", "   ", "line"]

    def test_strip_leading_blank_lines(self):
        list_text_lead_blank_lines = ["", "test"]
        test_queue_blank_lines = Queue()

        # putting text in lines into queue
        for word in list_text_lead_blank_lines:
            test_queue_blank_lines.put(word)

        # execute the tested function
        strip_leading_blank_lines(test_queue_blank_lines)

        # covert the queue back to list and assert  `
        assert list(test_queue_blank_lines.queue) == ["test"]

    def test_strip_leading_chars(self):
        # create test piece in list of chars
        list_text_lead_chars = ["t", " ", "e", " ", " s", " ", "t"]
        test_queue_chars = Queue()

        # putting text into queue
        for char in list_text_lead_chars:
            test_queue_chars.put(char)

        # execute test function
        strip_leading_characters(char_queue=test_queue_chars, num_chars=5)
        # convert queue back to list of char and make assertion
        assert list(test_queue_chars.queue) == [" ", "t"]

    def test_strip_leading_words(self):
        list_text_lead_words = ["test", " ", " ", "test", "test"]
        test_queue_words = Queue()

        # putting text into test queue
        for word in list_text_lead_words:
            test_queue_words.put(word)

        # execute the test function
        strip_leading_words(word_queue=test_queue_words, num_words=2)
        # convert queue back to list and assert
        assert list(test_queue_words.queue) == ["test"]

    def test_strip_leading_lines(self):
        list_text_lead_lines = ["test", " ", "test", " "]
        test_queue_lines = Queue()

        # putting text into test queue
        for line in list_text_lead_lines:
            test_queue_lines.put(line)

        # execute the test function
        strip_leading_lines(line_queue=test_queue_lines, num_lines=1)
        # convert queue back to list and assert
        assert list(test_queue_lines.queue) == ["test", " "]

@@ -230,17 +230,22 @@
 ng_lines
+, cut
 %0A
-
 %0A%0Aclass 
@@ -339,16 +339,17 @@
 espace(%22
+ 
 the   st
@@ -371,16 +371,25 @@
         
+ %22%22, %22 %22,
  %22the%22, 
@@ -1055,24 +1055,59 @@
 %22, %22line%22%5D%0A%0A
+    # this unit test DOES NOT work%0A
     def test
@@ -1566,32 +1566,36 @@
 ines.queue) == %5B
+%22%22, 
 %22test%22%5D%0A%0A    def
@@ -2588,32 +2588,131 @@
 e) == %5B%22test%22%5D%0A%0A
+    # this assertion DOES NOT work, since related to the%0A    # function of strp leading blank line%0A
     def test_str
@@ -3145,28 +3145,33 @@
 nes.queue) == %5B%22
+ %22, %22
 test%22, %22 %22%5D%0A
@@ -3154,24 +3154,439 @@
 ) == %5B%22 %22, %22test%22, %22 %22%5D%0A
+%0A%0Aclass TestCutterFunction:%0A    # the second assertion DOES NOT work%0A    def test_cutter_basic(self):%0A        assert cut(text=%22test%5Cntest%5Cntest%22, cutting_value='1',%0A                   cutting_type='lines', overlap='0', last_prop='0') == %5C%0A               %5B%22test%5Cn%22, %22test%5Cn%22, %22test%22%5D%0A        assert cut(text=%22test%22, cutting_value='1', cutting_type='words',%0A                   overlap='0', last_prop='0') == %5B%22test%22%5D%0A

add main cutter function unit test; revert unit test for function with bug