From 8820178149baf6c6411052975701794537d0b453 Mon Sep 17 00:00:00 2001 From: Anton Domashnev Date: Mon, 24 Aug 2015 21:54:53 +0200 Subject: [PATCH] Add russian expression - one; --- Swifternalization.xcodeproj/project.pbxproj | 10 ++++ .../SharedRussianExpression.swift | 46 +++++++++++++++++++ .../SharedRussianExpressionTests.swift | 46 +++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 Swifternalization/SharedRussianExpression.swift create mode 100644 SwifternalizationTests/SharedRussianExpressionTests.swift diff --git a/Swifternalization.xcodeproj/project.pbxproj b/Swifternalization.xcodeproj/project.pbxproj index 7bcf1ed..2aee51f 100644 --- a/Swifternalization.xcodeproj/project.pbxproj +++ b/Swifternalization.xcodeproj/project.pbxproj @@ -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 */; }; @@ -103,6 +106,8 @@ 6D140F431B56D03D00359143 /* RandomNumbers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RandomNumbers.swift; sourceTree = ""; }; 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 = ""; }; 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 = ""; }; 6D4C4EB21B6AAE3200B7839A /* LoadedTranslationsProcessor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoadedTranslationsProcessor.swift; sourceTree = ""; }; @@ -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 */, @@ -289,6 +295,7 @@ 6D19ABDA1B6D23730063FE1E /* SharedBaseExpression.swift */, 6D477E6F1B6D258F001F1904 /* SharedExpression.swift */, 6D19ABDB1B6D23730063FE1E /* SharedPolishExpression.swift */, + 6D43BA171B8BA8460072DEA6 /* SharedRussianExpression.swift */, ); path = "Shared Expressions"; sourceTree = ""; @@ -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 */, @@ -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 */, @@ -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 */, diff --git a/Swifternalization/SharedRussianExpression.swift b/Swifternalization/SharedRussianExpression.swift new file mode 100644 index 0000000..04d1524 --- /dev/null +++ b/Swifternalization/SharedRussianExpression.swift @@ -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]$)"), + ] + } +} diff --git a/SwifternalizationTests/SharedRussianExpressionTests.swift b/SwifternalizationTests/SharedRussianExpressionTests.swift new file mode 100644 index 0000000..673f228 --- /dev/null +++ b/SwifternalizationTests/SharedRussianExpressionTests.swift @@ -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") + } +}