-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06c9f69
commit 8820178
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// SharedRussianExpression.swift | ||
// Swifternalization | ||
// | ||
// Created by Anton Domashnev on 8/24/15. | ||
// Copyright (c) 2015 Tomasz Szulc. All rights reserved. | ||
// | ||
|
||
/** | ||
Contains Russian expressions. | ||
*/ | ||
class SharedRussianExpression: SharedExpressionProtocol { | ||
|
||
/** | ||
Return expressions that are valid in Poland. | ||
*/ | ||
static func allExpressions() -> [SharedExpression] { | ||
return [ | ||
/** | ||
1, 21, 31, 41, 51, 61, 71, 81, 101, 1001, … | ||
|
||
e.g. | ||
- из 1 книги за 1 день | ||
*/ | ||
SharedExpression(identifier: "one", pattern: "exp:(^1$)|(^[^1]1$)|(^[1-9][0-9]?[0,2,3,4,5,6,7,8,9]+1$)"), | ||
|
||
/** | ||
(2-4), (22-24), (32-4), ..., (..>22, ..>23, ..>24) | ||
|
||
e.g. | ||
- 22 samochody, 1334 samochody, 53 samochody | ||
- 2 minuty, 4 minuty, 23 minuty | ||
*/ | ||
SharedExpression(identifier: "few", pattern: "exp:(((?!1).[2-4]{1})$)|(^[2-4]$)"), | ||
|
||
/** | ||
0, (5-9), (10-21), (25-31), ..., (..0, ..1, ..5-9) | ||
|
||
e.g. | ||
- 0 samochodów, 10 samochodów, 26 samochodów, 1147 samochodów | ||
- 5 minut, 18 minut, 117 minut, 1009 minut | ||
*/ | ||
SharedExpression(identifier: "many", pattern: "exp:(^[05-9]$)|(.*(?=1).[0-9]$)|(^[0-9]{1}.*[0156789]$)"), | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// SharedRussianExpressionTests.swift | ||
// Swifternalization | ||
// | ||
// Created by Anton Domashnev on 8/24/15. | ||
// Copyright (c) 2015 Tomasz Szulc. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import XCTest | ||
|
||
class SharedRussianExpressionTests: XCTestCase { | ||
|
||
func testOne() { | ||
let sharedExp = SharedRussianExpression.allExpressions().filter({$0.identifier == "one"}).first! | ||
let expression = Expression(pattern: sharedExp.pattern, value: "") | ||
|
||
XCTAssertTrue(expression.validate("1"), "Should match 1") | ||
XCTAssertTrue(expression.validate("21"), "Should match 21") | ||
XCTAssertTrue(expression.validate("101"), "Should match 151") | ||
XCTAssertTrue(expression.validate("451"), "Should match 451") | ||
XCTAssertTrue(expression.validate("1441"), "Should match 1441") | ||
XCTAssertTrue(expression.validate("3441"), "Should match 3441") | ||
|
||
XCTAssertFalse(expression.validate("11"), "Should not match 11") | ||
XCTAssertFalse(expression.validate("25"), "Should not match 25") | ||
XCTAssertFalse(expression.validate("111"), "Should not match 111") | ||
XCTAssertFalse(expression.validate("1211"), "Should not match 1211") | ||
} | ||
|
||
func testMany() { | ||
let sharedExp = SharedPolishExpression.allExpressions().filter({$0.identifier == "many"}).first! | ||
let expression = Expression(pattern: sharedExp.pattern, value: "") | ||
|
||
XCTAssertTrue(expression.validate("10"), "Should match 10") | ||
XCTAssertTrue(expression.validate("18"), "Should match 18") | ||
XCTAssertTrue(expression.validate("1009"), "Should match 1009") | ||
|
||
XCTAssertFalse(expression.validate("22"), "Should not match 22") | ||
XCTAssertFalse(expression.validate("24"), "Should not match 24") | ||
XCTAssertFalse(expression.validate("153"), "Should not match 153") | ||
XCTAssertFalse(expression.validate("454"), "Should not match 454") | ||
XCTAssertFalse(expression.validate("1443"), "Should not match 1443") | ||
XCTAssertFalse(expression.validate("3443"), "Should not match 3443") | ||
} | ||
} |