tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test.py (1396B)


      1 #!/usr/bin/env python
      2 #
      3 # This Source Code Form is subject to the terms of the Mozilla Public
      4 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
      5 # You can obtain one at http://mozilla.org/MPL/2.0/.
      6 
      7 import mozunit
      8 import pytest
      9 from mozshellutil import MetaCharacterException, quote, split
     10 
     11 
     12 def test_quote_simple():
     13    assert quote("a", "b") == "a b"
     14 
     15 
     16 def test_quote_with_spaces():
     17    assert quote("a b", "c") == "'a b' c"
     18 
     19 
     20 def test_quote_empty_string():
     21    assert quote("") == "''"
     22 
     23 
     24 def test_quote_single_quote():
     25    assert quote("a'b") == "'a'\\''b'"
     26 
     27 
     28 def test_quote_with_special_chars():
     29    result = quote("a$b")
     30    assert result == "'a$b'"
     31 
     32 
     33 def test_quote_int():
     34    assert quote(123) == "123"
     35 
     36 
     37 def test_split_simple():
     38    assert split("a b c") == ["a", "b", "c"]
     39 
     40 
     41 def test_split_quoted():
     42    assert split("'a b' c") == ["a b", "c"]
     43 
     44 
     45 def test_split_double_quoted():
     46    assert split('"a b" c') == ["a b", "c"]
     47 
     48 
     49 def test_split_escaped():
     50    assert split(r"a\ b c") == ["a b", "c"]
     51 
     52 
     53 def test_split_with_comment():
     54    assert split("a b # comment") == ["a", "b"]
     55 
     56 
     57 def test_split_metacharacter_exception():
     58    with pytest.raises(MetaCharacterException) as exc_info:
     59        split("a | b")
     60    assert exc_info.value.char == "|"
     61 
     62 
     63 def test_split_escaped_newlines():
     64    assert split("a\\\nb") == ["ab"]
     65 
     66 
     67 if __name__ == "__main__":
     68    mozunit.main()