Skip to content

Commit

Permalink
Add russian expression - one;
Browse files Browse the repository at this point in the history
  • Loading branch information
Antondomashnev committed Aug 24, 2015
1 parent 06c9f69 commit 8820178
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Swifternalization.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
6D19ABDD1B6D23730063FE1E /* SharedBaseExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D19ABDA1B6D23730063FE1E /* SharedBaseExpression.swift */; };
6D19ABDE1B6D23730063FE1E /* SharedPolishExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D19ABDB1B6D23730063FE1E /* SharedPolishExpression.swift */; };
6D19ABDF1B6D23730063FE1E /* SharedPolishExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D19ABDB1B6D23730063FE1E /* SharedPolishExpression.swift */; };
6D43BA181B8BA8460072DEA6 /* SharedRussianExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D43BA171B8BA8460072DEA6 /* SharedRussianExpression.swift */; };
6D43BA1A1B8BA8C20072DEA6 /* SharedRussianExpressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D43BA191B8BA8C20072DEA6 /* SharedRussianExpressionTests.swift */; };
6D43BA1B1B8BADB50072DEA6 /* SharedRussianExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D43BA171B8BA8460072DEA6 /* SharedRussianExpression.swift */; };
6D477E701B6D258F001F1904 /* SharedExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D477E6F1B6D258F001F1904 /* SharedExpression.swift */; };
6D477E711B6D258F001F1904 /* SharedExpression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D477E6F1B6D258F001F1904 /* SharedExpression.swift */; };
6D4C4EAF1B6AA48F00B7839A /* LoadedTranslation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D4C4EAE1B6AA48F00B7839A /* LoadedTranslation.swift */; };
Expand Down Expand Up @@ -103,6 +106,8 @@
6D140F431B56D03D00359143 /* RandomNumbers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RandomNumbers.swift; sourceTree = "<group>"; };
6D19ABDA1B6D23730063FE1E /* SharedBaseExpression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SharedBaseExpression.swift; path = Swifternalization/SharedBaseExpression.swift; sourceTree = SOURCE_ROOT; };
6D19ABDB1B6D23730063FE1E /* SharedPolishExpression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SharedPolishExpression.swift; path = Swifternalization/SharedPolishExpression.swift; sourceTree = SOURCE_ROOT; };
6D43BA171B8BA8460072DEA6 /* SharedRussianExpression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SharedRussianExpression.swift; path = Swifternalization/SharedRussianExpression.swift; sourceTree = SOURCE_ROOT; };
6D43BA191B8BA8C20072DEA6 /* SharedRussianExpressionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SharedRussianExpressionTests.swift; sourceTree = "<group>"; };
6D477E6F1B6D258F001F1904 /* SharedExpression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SharedExpression.swift; path = Swifternalization/SharedExpression.swift; sourceTree = SOURCE_ROOT; };
6D4C4EAE1B6AA48F00B7839A /* LoadedTranslation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoadedTranslation.swift; sourceTree = "<group>"; };
6D4C4EB21B6AAE3200B7839A /* LoadedTranslationsProcessor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoadedTranslationsProcessor.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -247,6 +252,7 @@
6DD3B9431B5ED55500C79EAC /* SharedExpressionsLoaderTests.swift */,
6D5BA6031B6537D5000D7E49 /* SharedExpressionsProcessorTests.swift */,
6DBB6C971B4077FA002F39A3 /* SharedPolishExpressionTests.swift */,
6D43BA191B8BA8C20072DEA6 /* SharedRussianExpressionTests.swift */,
6D50045A1B3EF91600A54B36 /* SwifternalizationTests.swift */,
6D5BA5EF1B651796000D7E49 /* TranslationsLoaderTests.swift */,
6D6282931B3F052B00E65FCD /* TranslatablePairTests.swift */,
Expand Down Expand Up @@ -289,6 +295,7 @@
6D19ABDA1B6D23730063FE1E /* SharedBaseExpression.swift */,
6D477E6F1B6D258F001F1904 /* SharedExpression.swift */,
6D19ABDB1B6D23730063FE1E /* SharedPolishExpression.swift */,
6D43BA171B8BA8460072DEA6 /* SharedRussianExpression.swift */,
);
path = "Shared Expressions";
sourceTree = "<group>";
Expand Down Expand Up @@ -435,6 +442,7 @@
6D6282A31B3F247000E65FCD /* ExpressionMatcher.swift in Sources */,
6D5004661B3EF92600A54B36 /* Swifternalization.swift in Sources */,
6D62829A1B3F17CA00E65FCD /* Regex.swift in Sources */,
6D43BA181B8BA8460072DEA6 /* SharedRussianExpression.swift in Sources */,
6D6282B51B3F3C4100E65FCD /* InequalitySign.swift in Sources */,
6D4C4EBD1B6ABE0700B7839A /* Translation.swift in Sources */,
6DB3CC901B5EC29600A1220F /* ExpressionPatternType.swift in Sources */,
Expand Down Expand Up @@ -465,6 +473,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
6D43BA1B1B8BADB50072DEA6 /* SharedRussianExpression.swift in Sources */,
6D6282C91B3F4F6700E65FCD /* RegexExpressionParser.swift in Sources */,
6DBB6C981B4077FA002F39A3 /* SharedPolishExpressionTests.swift in Sources */,
6DD3B9441B5ED55500C79EAC /* SharedExpressionsLoaderTests.swift in Sources */,
Expand Down Expand Up @@ -493,6 +502,7 @@
6DBB6C521B401B8A002F39A3 /* Swifternalization.swift in Sources */,
6D5BA5F01B651796000D7E49 /* TranslationsLoaderTests.swift in Sources */,
6D4C4EC41B6ACF2C00B7839A /* Translation.swift in Sources */,
6D43BA1A1B8BA8C20072DEA6 /* SharedRussianExpressionTests.swift in Sources */,
6D6282BF1B3F42CA00E65FCD /* InequalityExpressionMatcherTests.swift in Sources */,
6D5BA6041B6537D5000D7E49 /* SharedExpressionsProcessorTests.swift in Sources */,
6D6282B31B3F3C2800E65FCD /* InequalityExtendedExpressionParser.swift in Sources */,
Expand Down
46 changes: 46 additions & 0 deletions Swifternalization/SharedRussianExpression.swift
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]$)"),
]
}
}
46 changes: 46 additions & 0 deletions SwifternalizationTests/SharedRussianExpressionTests.swift
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")
}
}

0 comments on commit 8820178

Please sign in to comment.