-1

I wrote simple test:

   func testTabs() {
        let tabbed = "\t"
        let spaced = "    "

        XCTAssert(tabbed == spaced, "Comparison is illegal")
    }

   func testTabs() {
        let tabbed = "\t"
        let tab = "    "

        XCTAssert(tabbed == tab, "Comparison is illegal")
    }

if fails for using actual 'tab' spacing, it fails for 4 spaces,2 spaces. So I compare tab for \t and it fails. ( also fails for any equivalent).

Should it work at all? Should I never use tab in strings if I want do the tests? Let me show what I mean:

func generateSomeString() -> String {
    let array = ["Some","Stupid","People","Don't","Read","But","Comment"]
    let string = array.joined(separator: "\t")
    return string
}

func testStrings() {
    let string = generateSomeString()
    let expectedString = "Some    Stupid    People    Don't    Read    But    Comment"
    print(string)
    XCTAssert(string == expectedString, "Comparison is illegal")
}
Zaporozhchenko Oleksandr
  • 4,660
  • 3
  • 26
  • 48

1 Answers1

0

Tabs and spaces are whitespace, but are not the same thing.

You can replace \t to an expected number of spaces, and then test it...

thedp
  • 8,350
  • 16
  • 53
  • 95
  • ye, that workaround will work for sure. But it also means, I never can use \t in my strings if I want to use tests. or I need to replace all spaces(and/or tabs) in constant strings with \t and loose their visuality and readability. – Zaporozhchenko Oleksandr Feb 18 '18 at 13:26