Skip to content

Commit

Permalink
Bug fix to convertPosition with unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ranganath Atreya committed Sep 15, 2019
1 parent 94c5328 commit fb16873
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Source/Transliterator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public class Transliterator {

- Parameters:
- position: index position within the aggregate `Transliterator` state specified in `fromUnits`
- fromUnits: `PositionalUnits` of the input `position`
- fromUnits: `PositionalUnits` of the `position` parameter
- toUnits: desired `PositionalUnits` of the returned value
- Returns: index corrosponding to input `position` in `toUnits` of the aggregate state or `nil` if the position is invalid
*/
Expand Down Expand Up @@ -153,7 +153,7 @@ public class Transliterator {
}
index += 1
}
return position
return result
}

/**
Expand Down
16 changes: 16 additions & 0 deletions Tests/TransliteratorTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,22 @@ class TransliteratorTest: XCTestCase {
let idemResult: Literated = transliterator.transliterate("kRRI")
XCTAssertEqual(idemResult.finalaizedOutput + idemResult.unfinalaizedOutput, "कॄ")
}

func testConvertPosition() throws {
let transliterator = try factory!.transliterator(schemeName: "Barahavat", scriptName: "Devanagari")
let result: Literated = transliterator.transliterate("aatreya")
XCTAssertEqual(result.finalaizedOutput, "आत्")
XCTAssertEqual(result.unfinalaizedOutput, "रेय")
let pos1 = transliterator.convertPosition(position: 7, fromUnits: .input, toUnits: .outputScalar)
XCTAssertEqual(pos1, 6)
let pos2 = transliterator.convertPosition(position: 2, fromUnits: .input, toUnits: .outputChar)
XCTAssertEqual(pos2, 1)
let pos3 = transliterator.convertPosition(position: 2, fromUnits: .outputScalar, toUnits: .input)
XCTAssertEqual(pos3, 3)
_ = transliterator.delete()
let pos4 = transliterator.convertPosition(position: 6, fromUnits: .input, toUnits: .outputScalar)
XCTAssertEqual(pos4, 7)
}

func testInitPerformance() {
self.measure {
Expand Down

0 comments on commit fb16873

Please sign in to comment.