├── .gitignore ├── README.markdown ├── build.xml ├── cheatsheet.md ├── hamcrest-unit-test ├── .actionScriptProperties ├── .flexProperties ├── .project ├── libs │ ├── flexunit-4.0.0.swc │ ├── flexunit-cilistener-4.0.0.swc │ ├── flexunit-uilistener-4.0.0.swc │ └── mockolate.swc └── src │ ├── HamcrestComponentManifestXmlnsExample.mxml │ ├── HamcrestMXMLExample.mxml │ ├── HamcrestTestRunner.mxml │ └── org │ └── hamcrest │ ├── AbstractMatcherTestCase.as │ ├── AssertThatTest.as │ ├── BaseMatcherTest.as │ ├── CustomMatcherTest.as │ ├── CustomTypeSafeMatcherTest.as │ ├── DescriptionTest.as │ ├── HamcrestMXMLSuite.as │ ├── HamcrestSuite.as │ ├── MatcherAssertTest.as │ ├── TypeSafeMatcherTest.as │ ├── collection │ ├── AbstractArrayMatcherTestCase.as │ ├── EveryByMatcherTest.as │ ├── EveryTest.as │ ├── FilterByMatcherTest.as │ ├── InArrayTest.as │ ├── IndexOfByMatcherTest.as │ ├── IndexesOfByMatcherTest.as │ ├── IsArrayContainingTest.as │ ├── IsArrayTest.as │ ├── IsArrayWithSizeTest.as │ ├── RejectByMatcherTest.as │ ├── SomeByMatcherTest.as │ ├── SortedByFieldsTest.as │ └── SortedByTest.as │ ├── core │ ├── AllOfTest.as │ ├── AnyOfTest.as │ ├── CombinableTest.as │ ├── DescribedAsTest.as │ ├── EvaluateTest.as │ ├── GivenTest.as │ ├── IsAnythingTest.as │ ├── IsNotTest.as │ ├── IsNothingTest.as │ └── ThrowsTest.as │ ├── date │ ├── DateAfterTest.as │ ├── DateBeforeTest.as │ ├── DateBetweenTest.as │ ├── DateEqualTest.as │ └── describeDate.as │ ├── filter │ └── FilterFunctionTest.as │ ├── mxml │ ├── AbstractMXMLMatcherTestCase.as │ ├── BaseMXMLMatcherCompositeTest.as │ ├── BaseMXMLMatcherContainerTest.as │ ├── BaseMXMLMatcherTest.as │ ├── collection │ │ ├── ArrayTest.as │ │ ├── ArrayWithSizeTest.as │ │ ├── EmptyArrayTest.as │ │ ├── EveryItemTest.as │ │ ├── HasItemTest.as │ │ ├── HasItemsTest.as │ │ └── InArrayTest.as │ ├── core │ │ ├── AllOfTest.as │ │ ├── AnyOfTest.as │ │ ├── AnythingTest.as │ │ ├── BaseMXMLMatcherTest.as │ │ ├── DescribedAsTest.as │ │ ├── HamcrestMxmlExample.mxml │ │ └── NotTest.as │ ├── date │ │ ├── DateAfterTest.as │ │ ├── DateBeforeTest.as │ │ ├── DateBetweenTest.as │ │ └── DateEqualToTest.as │ ├── number │ │ ├── BetweenTest.as │ │ ├── CloseToTest.as │ │ ├── GreaterThanOrEqualToTest.as │ │ ├── GreaterThanTest.as │ │ ├── LessThanOrEqualToTest.as │ │ └── LessThanTest.as │ ├── object │ │ ├── EqualToTest.as │ │ ├── HasPropertyChainTest.as │ │ ├── HasPropertyTest.as │ │ ├── HasPropertyWithValueTest.as │ │ ├── InstanceOfTest.as │ │ ├── IsFalseTest.as │ │ ├── IsTrueTest.as │ │ ├── NotNullTest.as │ │ ├── NullTest.as │ │ └── SameInstanceTest.as │ └── text │ │ ├── ContainsStringTest.as │ │ ├── EmptyStringTest.as │ │ ├── EndsWithTest.as │ │ └── StartsWithTest.as │ ├── number │ ├── AtLeastTest.as │ ├── AtMostTest.as │ ├── BetweenTest.as │ ├── CloseToTest.as │ ├── GreaterThanTest.as │ ├── IsNotANumberTest.as │ ├── IsNumberTest.as │ └── LessThanTest.as │ ├── object │ ├── HasPropertiesTest.as │ ├── HasPropertyChainTest.as │ ├── HasPropertyTest.as │ ├── HasPropertyWithValueTest.as │ ├── IsEqualTest.as │ ├── IsFalseTest.as │ ├── IsInstanceOfTest.as │ ├── IsInterfaceTest.as │ ├── IsNotNullTest.as │ ├── IsNullTest.as │ ├── IsSameTest.as │ ├── IsStrictlyEqualTest.as │ ├── IsTrueTest.as │ └── NullOrMatcherTest.as │ ├── test │ └── support │ │ ├── ExampleClass.as │ │ ├── ExampleInterface.as │ │ ├── ExtendedExampleInterface.as │ │ └── ImplementingExampleClass.as │ ├── text │ ├── ContainsStringsTest.as │ ├── EmptyStringTest.as │ ├── StringContainsTest.as │ ├── StringEndsWithTest.as │ └── StringStartsWithTest.as │ └── validation │ └── MatcherValidatorTest.as ├── hamcrest ├── .actionScriptProperties ├── .flexLibProperties ├── .project ├── LICENSE ├── build-docs.sh ├── build-swc.sh ├── src-flex │ ├── hamcrest-manifest.xml │ └── org │ │ └── hamcrest │ │ ├── collection │ │ ├── everyByMatcher.as │ │ ├── filterByMatcher.as │ │ ├── indexOfByMatcher.as │ │ ├── indexesOfByMatcher.as │ │ ├── rejectByMatcher.as │ │ └── someByMatcher.as │ │ ├── filter │ │ ├── FilterFunction.as │ │ └── IFilterFunction.as │ │ ├── mxml │ │ ├── BaseMXMLMatcher.as │ │ ├── BaseMXMLMatcherComposite.as │ │ ├── BaseMXMLMatcherContainer.as │ │ ├── MXMLMatcher.as │ │ ├── MXMLMatcherComposite.as │ │ ├── MXMLMatcherContainer.as │ │ ├── collection │ │ │ ├── Array.as │ │ │ ├── ArrayWithSize.as │ │ │ ├── EmptyArray.as │ │ │ ├── EveryItem.as │ │ │ ├── HasItem.as │ │ │ ├── HasItems.as │ │ │ └── InArray.as │ │ ├── core │ │ │ ├── AllOf.as │ │ │ ├── AnyOf.as │ │ │ ├── Anything.as │ │ │ ├── DescribedAs.as │ │ │ ├── Evaluate.as │ │ │ ├── Given.as │ │ │ └── Not.as │ │ ├── date │ │ │ ├── DateAfter.as │ │ │ ├── DateBefore.as │ │ │ ├── DateBetween.as │ │ │ └── DateEqualTo.as │ │ ├── number │ │ │ ├── Between.as │ │ │ ├── CloseTo.as │ │ │ ├── GreaterThan.as │ │ │ ├── GreaterThanOrEqualTo.as │ │ │ ├── LessThan.as │ │ │ └── LessThanOrEqualTo.as │ │ ├── object │ │ │ ├── EqualTo.as │ │ │ ├── HasProperties.as │ │ │ ├── HasProperty.as │ │ │ ├── HasPropertyChain.as │ │ │ ├── InstanceOf.as │ │ │ ├── IsFalse.as │ │ │ ├── IsTrue.as │ │ │ ├── NotNull.as │ │ │ ├── Null.as │ │ │ └── SameInstance.as │ │ └── text │ │ │ ├── ContainsString.as │ │ │ ├── EmptyString.as │ │ │ ├── EndsWith.as │ │ │ ├── MatchesPattern.as │ │ │ ├── StartsWith.as │ │ │ └── StringMXMLMatcher.as │ │ └── validator │ │ └── MatcherValidator.as └── src │ ├── hamcrest-config.xml │ └── org │ └── hamcrest │ ├── AssertionError.as │ ├── BaseDescription.as │ ├── BaseMatcher.as │ ├── CustomMatcher.as │ ├── CustomTypeSafeMatcher.as │ ├── Description.as │ ├── DiagnosingMatcher.as │ ├── Matcher.as │ ├── NullDescription.as │ ├── SelfDescribing.as │ ├── StringDescription.as │ ├── TypeSafeDiagnosingMatcher.as │ ├── TypeSafeMatcher.as │ ├── assertThat.as │ ├── assertThatBoolean.as │ ├── assertThatMatcher.as │ ├── collection │ ├── EveryMatcher.as │ ├── InArrayMatcher.as │ ├── IsArrayContainingMatcher.as │ ├── IsArrayMatcher.as │ ├── IsArrayWithSizeMatcher.as │ ├── SortedByFieldsMatcher.as │ ├── SortedByMatcher.as │ ├── array.as │ ├── arrayWithSize.as │ ├── emptyArray.as │ ├── everyItem.as │ ├── hasItem.as │ ├── hasItems.as │ ├── inArray.as │ ├── sortedBy.as │ └── sortedByFields.as │ ├── core │ ├── AllOfMatcher.as │ ├── AnyOfMatcher.as │ ├── CombinableMatcher.as │ ├── DescribedAsMatcher.as │ ├── EvaluateMatcher.as │ ├── GivenMatcher.as │ ├── IsAnythingMatcher.as │ ├── IsMatcher.as │ ├── IsNotMatcher.as │ ├── IsNothingMatcher.as │ ├── ShortcutCombinationMatcher.as │ ├── ThrowsMatcher.as │ ├── allOf.as │ ├── anyOf.as │ ├── anything.as │ ├── both.as │ ├── describedAs.as │ ├── describedAsWithMismatch.as │ ├── either.as │ ├── evaluate.as │ ├── given.as │ ├── isA.as │ ├── not.as │ ├── nothing.as │ └── throws.as │ ├── date │ ├── DateAfterMatcher.as │ ├── DateBeforeMatcher.as │ ├── DateEqualMatcher.as │ ├── dateAfter.as │ ├── dateAfterOrEqual.as │ ├── dateBefore.as │ ├── dateBeforeOrEqual.as │ ├── dateBetween.as │ └── dateEqual.as │ ├── number │ ├── IsCloseToMatcher.as │ ├── IsGreaterThanMatcher.as │ ├── IsLessThanMatcher.as │ ├── IsNotANumberMatcher.as │ ├── IsNumberMatcher.as │ ├── atLeast.as │ ├── atMost.as │ ├── between.as │ ├── closeTo.as │ ├── greaterThan.as │ ├── greaterThanOrEqualTo.as │ ├── isNotANumber.as │ ├── isNumber.as │ ├── lessThan.as │ └── lessThanOrEqualTo.as │ ├── object │ ├── HasPropertiesMatcher.as │ ├── HasPropertyChainMatcher.as │ ├── HasPropertyMatcher.as │ ├── HasPropertyWithValueMatcher.as │ ├── IsEqualMatcher.as │ ├── IsFalseMatcher.as │ ├── IsInstanceOfMatcher.as │ ├── IsInterfaceMatcher.as │ ├── IsNullMatcher.as │ ├── IsSameMatcher.as │ ├── IsStrictlyEqualMatcher.as │ ├── IsTrueMatcher.as │ ├── equalTo.as │ ├── hasProperties.as │ ├── hasProperty.as │ ├── hasPropertyChain.as │ ├── hasPropertyWithValue.as │ ├── instanceOf.as │ ├── isFalse.as │ ├── isFalsey.as │ ├── isInterface.as │ ├── isNotNull.as │ ├── isNull.as │ ├── isTrue.as │ ├── isTruthy.as │ ├── notNullValue.as │ ├── nullOr.as │ ├── nullValue.as │ ├── sameInstance.as │ └── strictlyEqualTo.as │ └── text │ ├── ContainsStringsMatcher.as │ ├── EmptyStringMatcher.as │ ├── RegExpMatcher.as │ ├── StringContainsMatcher.as │ ├── StringEndsWithMatcher.as │ ├── StringStartsWithMatcher.as │ ├── SubstringMatcher.as │ ├── containsString.as │ ├── containsStrings.as │ ├── emptyString.as │ ├── endsWith.as │ ├── re.as │ └── startsWith.as ├── libs └── build │ ├── as3-parser-1.1.jar │ ├── as3-parser-api-1.1.jar │ ├── as3-plugin-utils-1.1.jar │ ├── commons-lang-2.4.jar │ ├── dom4j-1.6.1.jar │ ├── flex-pmd-ant-task-1.1.jar │ ├── flex-pmd-command-line-1.1.jar │ ├── flex-pmd-command-line-api-1.1.jar │ ├── flex-pmd-core-1.1.jar │ ├── flex-pmd-cpd-1.1.jar │ ├── flex-pmd-cpd-ant-task-1.1.jar │ ├── flex-pmd-cpd-command-line-1.1.jar │ ├── flex-pmd-files-1.1.jar │ ├── flex-pmd-metrics-1.1.jar │ ├── flex-pmd-metrics-ant-task-1.1.jar │ ├── flex-pmd-metrics-command-line-1.1.jar │ ├── flex-pmd-ruleset-1.1.jar │ ├── flex-pmd-ruleset-api-1.1.jar │ ├── flexUnitTasks-4.0.0.jar │ ├── jsap-2.1.jar │ ├── plexus-utils-1.0.2.jar │ └── pmd-4.2.5.jar ├── pmd-ruleset.xml └── version.properties /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .settings 3 | bin 4 | doc 5 | bin-debug 6 | html-template 7 | target 8 | FlexUnitApplication.mxml 9 | FlexUnitCompilerApplication.mxml 10 | .FlexUnitSettings 11 | *.iml 12 | *.ipr 13 | *.iws 14 | .project 15 | -------------------------------------------------------------------------------- /hamcrest-unit-test/.flexProperties: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /hamcrest-unit-test/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | hamcrest-unit-test 4 | 5 | 6 | 7 | 8 | 9 | com.adobe.flexbuilder.project.flexbuilder 10 | 11 | 12 | 13 | 14 | 15 | com.adobe.flexbuilder.project.flexnature 16 | com.adobe.flexbuilder.project.actionscriptnature 17 | 18 | 19 | -------------------------------------------------------------------------------- /hamcrest-unit-test/libs/flexunit-4.0.0.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/hamcrest-unit-test/libs/flexunit-4.0.0.swc -------------------------------------------------------------------------------- /hamcrest-unit-test/libs/flexunit-cilistener-4.0.0.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/hamcrest-unit-test/libs/flexunit-cilistener-4.0.0.swc -------------------------------------------------------------------------------- /hamcrest-unit-test/libs/flexunit-uilistener-4.0.0.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/hamcrest-unit-test/libs/flexunit-uilistener-4.0.0.swc -------------------------------------------------------------------------------- /hamcrest-unit-test/libs/mockolate.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/hamcrest-unit-test/libs/mockolate.swc -------------------------------------------------------------------------------- /hamcrest-unit-test/src/HamcrestTestRunner.mxml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 28 | 29 | 30 | 31 | Application { 32 | backgroundColor: #3872b2; 33 | backgroundGradientColors: #3872b2, #0c1a3d; 34 | backgroundGradientAlphas: 1, 1; 35 | themeColor: #ffffff; 36 | color: #444444; 37 | fontFamily: "Myriad Pro Semibold"; 38 | fontSize: 12; 39 | } 40 | 41 | 42 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/AbstractMatcherTestCase.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest 2 | { 3 | 4 | import org.flexunit.Assert; 5 | 6 | public class AbstractMatcherTestCase extends Assert 7 | { 8 | 9 | public function assertMatches(message:String, matcher:Matcher, arg:Object):void 10 | { 11 | assertTrue(message, matcher.matches(arg)); 12 | } 13 | 14 | public function assertDoesNotMatch(message:String, matcher:Matcher, arg:Object):void 15 | { 16 | assertFalse(message, matcher.matches(arg)); 17 | } 18 | 19 | public function assertDescription(expected:String, matcher:Matcher):void 20 | { 21 | var description:Description = new StringDescription(); 22 | description.appendDescriptionOf(matcher); 23 | assertEquals("Expected description", expected, description.toString()); 24 | } 25 | 26 | public function assertMismatch(expected:String, matcher:Matcher, arg:Object):void 27 | { 28 | assertFalse("Precondition: Matcher should not match item.", matcher.matches(arg)); 29 | 30 | var description:Description = new StringDescription(); 31 | description.appendMismatchOf(matcher, arg); 32 | assertEquals("Expected mismatch description", expected, description.toString()); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/BaseMatcherTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest 2 | { 3 | public class BaseMatcherTest extends AbstractMatcherTestCase 4 | { 5 | [Test] 6 | public function describesItselfWithToStringMethod():void 7 | { 8 | var matcher:BaseMatcher = new BaseMatcherForTesting(); 9 | assertEquals("SOME DESCRIPTION", matcher.toString()); 10 | } 11 | } 12 | } 13 | 14 | import org.hamcrest.BaseMatcher; 15 | import org.hamcrest.Description; 16 | 17 | internal class BaseMatcherForTesting extends BaseMatcher 18 | { 19 | override public function describeTo(description:Description):void 20 | { 21 | description.appendText("SOME DESCRIPTION"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/CustomMatcherTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest 2 | { 3 | public class CustomMatcherTest extends AbstractMatcherTestCase 4 | { 5 | [Test] 6 | public function usesStaticDescription():void 7 | { 8 | var matcher:Matcher = new CustomMatcher("I match Strings", function(item:Object):Boolean { 9 | return (item is String); 10 | }); 11 | 12 | assertDescription("I match Strings", matcher); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/CustomTypeSafeMatcherTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest 2 | { 3 | 4 | public class CustomTypeSafeMatcherTest extends AbstractMatcherTestCase 5 | { 6 | 7 | private static const STATIC_DESCRIPTION:String = "I match non empty Strings"; 8 | 9 | [Test] 10 | public function usesStaticDescription():void 11 | { 12 | 13 | var matcher:Matcher = new CustomTypeSafeMatcher(STATIC_DESCRIPTION, String, function(item:String):Boolean 14 | { 15 | return false; 16 | }) 17 | 18 | assertDescription(STATIC_DESCRIPTION, matcher); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/DescriptionTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest 2 | { 3 | import org.flexunit.runners.Parameterized; 4 | import org.hamcrest.object.equalTo; 5 | 6 | Parameterized; 7 | 8 | [RunWith("org.flexunit.runners.Parameterized")] 9 | public class DescriptionTest 10 | { 11 | public var description:Description; 12 | 13 | [Before] 14 | public function setup():void 15 | { 16 | description = new StringDescription(); 17 | } 18 | 19 | public static function appendValueData():Array 20 | { 21 | return [ 22 | [true, ''], 23 | [false, ''], 24 | ['', '""'], 25 | ['String', '"String"'], 26 | [NaN, ''], 27 | [0, '<0>'], 28 | [-1, '<-1>'], 29 | [1, '<1>'], 30 | [123, '<123>'], 31 | [int(0), '<0>'], 32 | [int(-1), '<-1>'], 33 | [int(1), '<1>'], 34 | [int(123), '<123>'], 35 | [uint(0), '<0>'], 36 | [uint(1), '<1>'], 37 | [uint(123), '<123>'], 38 | [[], '[]'], 39 | [[1, 2, 3], '[<1>,<2>,<3>]'], 40 | [new XML(z), 'z'], 41 | [function():void {}, ''], 42 | [new Date(2000, 1, 1, 6, 7, 8, 9), "<2000-02-01T06:07:08.009>"] 43 | ]; 44 | } 45 | 46 | [Test(dataProvider="appendValueData")] 47 | public function appendValue(value:*, expected:String):void 48 | { 49 | description = new StringDescription(); 50 | description.appendValue(value); 51 | assertThat(description.toString(), equalTo(expected)); 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/TypeSafeMatcherTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest 2 | { 3 | 4 | public class TypeSafeMatcherTest extends AbstractMatcherTestCase 5 | { 6 | 7 | [Test] 8 | public function classMatchesSafelyIfTypesMatch():void 9 | { 10 | 11 | var called:Boolean = false; 12 | 13 | var matcher:TypeSafeMatcher = new TypeSafeMatcherForTesting(String, function(item:Object):Boolean 14 | { 15 | called = true; 16 | return true; 17 | }); 18 | 19 | matcher.matches("hello"); 20 | 21 | assertThat("TypeSafeMatcher.matchesSafely was not called", called); 22 | } 23 | } 24 | } 25 | 26 | import org.hamcrest.TypeSafeMatcher; 27 | 28 | internal class TypeSafeMatcherForTesting extends TypeSafeMatcher 29 | { 30 | 31 | private var _fn:Function; 32 | 33 | public function TypeSafeMatcherForTesting(type:Class, fn:Function) 34 | { 35 | super(type); 36 | _fn = fn; 37 | } 38 | 39 | override public function matchesSafely(item:Object):Boolean 40 | { 41 | return _fn(item); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/collection/AbstractArrayMatcherTestCase.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.collection 2 | { 3 | import mx.collections.ArrayCollection; 4 | 5 | import org.hamcrest.AbstractMatcherTestCase; 6 | import org.hamcrest.Matcher; 7 | 8 | public class AbstractArrayMatcherTestCase extends AbstractMatcherTestCase 9 | { 10 | public function AbstractArrayMatcherTestCase() 11 | { 12 | super(); 13 | } 14 | 15 | override public function assertMatches(message:String, matcher:Matcher, arg:Object):void 16 | { 17 | super.assertMatches(message, matcher, arg); 18 | 19 | // To ensure that the matcher properly matches non-Array collecitons, 20 | // run the same test again, this time using an ArrayCollection. 21 | if (arg is Array) 22 | { 23 | super.assertMatches(message + " (as ArrayCollection)", matcher, new ArrayCollection(arg as Array)); 24 | } 25 | } 26 | 27 | override public function assertDoesNotMatch(message:String, matcher:Matcher, arg:Object):void 28 | { 29 | super.assertDoesNotMatch(message, matcher, arg); 30 | 31 | // To ensure that the matcher properly matches non-Array collecitons, 32 | // run the same test again, this time using an ArrayCollection. 33 | if (arg is Array) 34 | { 35 | super.assertDoesNotMatch(message + " (as ArrayCollection)", matcher, new ArrayCollection(arg as Array)); 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/collection/EveryByMatcherTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.collection 2 | { 3 | import org.flexunit.assertThat; 4 | import org.hamcrest.number.isNumber; 5 | import org.hamcrest.object.isFalse; 6 | import org.hamcrest.object.isTrue; 7 | 8 | public class EveryByMatcherTest 9 | { 10 | [Test] 11 | public function with_all_matching_items_returns_true():void 12 | { 13 | var items:Array = [1, 2, 3, 4, 5]; 14 | 15 | assertThat(everyByMatcher(items, isNumber()), isTrue()); 16 | } 17 | 18 | [Test] 19 | public function with_any_mismatched_item_returns_false():void 20 | { 21 | var items:Array = [1, 2, false, 4, 5]; 22 | 23 | assertThat(everyByMatcher(items, isNumber()), isFalse()); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/collection/FilterByMatcherTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.collection 2 | { 3 | import org.flexunit.assertThat; 4 | import org.hamcrest.core.nothing; 5 | import org.hamcrest.number.greaterThan; 6 | 7 | public class FilterByMatcherTest 8 | { 9 | [Test] 10 | public function returns_matching_items():void 11 | { 12 | const items:Array = [1, 2, 3, 4, 5]; 13 | 14 | assertThat(filterByMatcher(items, greaterThan(2)), array(3, 4, 5)); 15 | } 16 | 17 | [Test] 18 | public function returns_empty_array_for_no_matching_items():void 19 | { 20 | const items:Array = [1, 2, 3, 4, 5]; 21 | 22 | assertThat(filterByMatcher(items, nothing()), emptyArray()); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/collection/InArrayTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.collection 2 | { 3 | public class InArrayTest extends AbstractArrayMatcherTestCase 4 | { 5 | [Test] 6 | public function matchesAnItemInArray():void 7 | { 8 | assertMatches( 9 | "should match 'a' for array that contains 'a'", 10 | inArray(['a', 'b', 'c']), 'a'); 11 | 12 | assertMatches( 13 | "should match 'a' for array that contains 'a'", 14 | inArray('a', 'b', 'c'), 'a'); 15 | } 16 | 17 | [Test] 18 | public function doesNotMatchIfNotInArray():void 19 | { 20 | assertDoesNotMatch( 21 | "should not match 'b' for array that does not contain 'b'", 22 | inArray(['b', 'c']), 'a'); 23 | 24 | assertDoesNotMatch( 25 | "should not match 'b' for array that does not contain 'b'", 26 | inArray('b', 'c'), 'a'); 27 | } 28 | 29 | [Test] 30 | public function hasAReadableDescription():void 31 | { 32 | assertDescription('contained in ["a", "b", "c"]', inArray(['a', 'b', 'c'])); 33 | assertDescription('contained in ["a", "b", "c"]', inArray('a', 'b', 'c')); 34 | } 35 | 36 | [Test] 37 | public function describesMismatch():void 38 | { 39 | assertMismatch( 40 | '"a" was not contained in ["b", "c"]', 41 | inArray('b', 'c'), 'a'); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/collection/IndexOfByMatcherTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.collection 2 | { 3 | import org.flexunit.assertThat; 4 | import org.hamcrest.object.equalTo; 5 | 6 | public class IndexOfByMatcherTest 7 | { 8 | [Test] 9 | public function returns_index_of_first_matching_item():void 10 | { 11 | const items:Array = [1, 2, 3, 2]; 12 | const SEARCH_ITEM:int = 2; 13 | const EXPECTED_INDEX:int = 1; 14 | 15 | assertThat("matches 2 at index 1", indexOfByMatcher(items, equalTo(SEARCH_ITEM)), equalTo(EXPECTED_INDEX)); 16 | } 17 | 18 | [Test] 19 | public function returns_index_of_first_matching_item_from_start_index():void 20 | { 21 | const items:Array = [1, 2, 3, 2]; 22 | const SEARCH_ITEM:int = 2; 23 | const START_INDEX:int = 2; 24 | const EXPECTED_INDEX:int = 3; 25 | 26 | assertThat("matches 2 at index 3", indexOfByMatcher(items, equalTo(SEARCH_ITEM), START_INDEX), equalTo(EXPECTED_INDEX)); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/collection/IndexesOfByMatcherTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.collection 2 | { 3 | import org.flexunit.assertThat; 4 | import org.hamcrest.number.greaterThan; 5 | 6 | public class IndexesOfByMatcherTest 7 | { 8 | [Test] 9 | public function returns_the_index_of_all_matching_items():void 10 | { 11 | const items:Array = [1, 2, 3, 2, 4]; 12 | 13 | assertThat(indexesOfByMatcher(items, greaterThan(2)), array(2, 4)); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/collection/RejectByMatcherTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.collection 2 | { 3 | import org.flexunit.assertThat; 4 | import org.hamcrest.core.anything; 5 | import org.hamcrest.core.nothing; 6 | import org.hamcrest.number.greaterThan; 7 | 8 | public class RejectByMatcherTest 9 | { 10 | [Test] 11 | public function returns_mismatched_items():void 12 | { 13 | const items:Array = [1, 2, 3, 4, 5]; 14 | 15 | assertThat(rejectByMatcher(items, greaterThan(2)), array(1, 2)); 16 | } 17 | 18 | [Test] 19 | public function returns_empty_array_if_every_item_matches():void 20 | { 21 | const items:Array = [1, 2, 3, 4, 5]; 22 | 23 | assertThat(rejectByMatcher(items, anything()), emptyArray()); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/collection/SomeByMatcherTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.collection 2 | { 3 | import org.flexunit.assertThat; 4 | import org.hamcrest.number.isNumber; 5 | import org.hamcrest.object.isFalse; 6 | import org.hamcrest.object.isTrue; 7 | 8 | public class SomeByMatcherTest 9 | { 10 | [Test] 11 | public function with_any_matching_items_returns_true():void 12 | { 13 | var items:Array = [false, 1, false, {}]; 14 | 15 | assertThat(someByMatcher(items, isNumber()), isTrue()); 16 | } 17 | 18 | [Test] 19 | public function with_no_matching_items_returns_false():void 20 | { 21 | var items:Array = [false, "1", false, {}]; 22 | 23 | assertThat(someByMatcher(items, isNumber()), isFalse()); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/core/EvaluateTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.core 2 | { 3 | import org.hamcrest.*; 4 | 5 | public class EvaluateTest extends AbstractMatcherTestCase 6 | { 7 | [Test] 8 | public function matchedIsTrueIfTrueExpression():void 9 | { 10 | assertMatches( "should match", evaluate( true ), "test" ); 11 | } 12 | 13 | [Test] 14 | public function matchedIsFalseIfFalseExpression():void 15 | { 16 | assertDoesNotMatch( "should not match", evaluate( false ), "test" ); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/core/GivenTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.core 2 | { 3 | import org.hamcrest.AbstractMatcherTestCase; 4 | 5 | public class GivenTest extends AbstractMatcherTestCase 6 | { 7 | [Test] 8 | public function matchedIsTrueIfTrueExpressionAndValueMatcherMatches():void 9 | { 10 | assertMatches( "should match", given( true, anything() ), "anything" ); 11 | assertMatches( "should match", given( true, anything(), false ), "anything" ); 12 | } 13 | 14 | [Test] 15 | public function matchedIsFalseIfTrueExpressionAndValueMatcherDoesNotMatch():void 16 | { 17 | assertDoesNotMatch( "should not match", given( true, not( anything() ) ), "anything" ); 18 | assertDoesNotMatch( "should not match", given( true, not( anything() ), false ), "anything" ); 19 | } 20 | 21 | [Test] 22 | public function matchedIsFalseIfFalseExpression():void 23 | { 24 | assertDoesNotMatch( "should not match", given( false, anything() ), "anything" ); 25 | assertDoesNotMatch( "should not match", given( false, anything(), false ), "anything" ); 26 | assertDoesNotMatch( "should not match", given( false, not( anything() ) ), "anything" ); 27 | assertDoesNotMatch( "should not match", given( false, not( anything() ), false ), "anything" ); 28 | } 29 | 30 | [Test] 31 | public function matchedIsTrueIfFalseExpressionAndOptionalOtherwiseSpecifiedAsTrue():void 32 | { 33 | assertMatches( "should match", given( false, not( anything() ), true ), "anything" ); 34 | assertMatches( "should match", given( false, not( anything() ), true ), "anything" ); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/core/IsAnythingTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.core 2 | { 3 | import org.hamcrest.*; 4 | 5 | public class IsAnythingTest extends AbstractMatcherTestCase 6 | { 7 | [Test] 8 | public function alwaysEvaluatesToTrue():void 9 | { 10 | assertThat(null, anything()); 11 | assertThat(new Object(), anything()); 12 | assertThat("hi", anything()); 13 | } 14 | 15 | [Test] 16 | public function hasUsefulDefaultDescription():void 17 | { 18 | assertDescription("ANYTHING", anything()); 19 | } 20 | 21 | [Test] 22 | public function canOverrideDescription():void 23 | { 24 | var description:String = "description"; 25 | assertDescription(description, anything(description)); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/core/IsNotTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.core 2 | { 3 | 4 | import org.hamcrest.*; 5 | import org.hamcrest.object.equalTo; 6 | 7 | public class IsNotTest extends AbstractMatcherTestCase 8 | { 9 | 10 | [Test] 11 | public function evaluatesToTheLogicalNegationOfAnotherMatcher():void 12 | { 13 | 14 | assertMatches("should match", not(equalTo("A")), "B"); 15 | assertDoesNotMatch("should not match", not(equalTo("B")), "B"); 16 | } 17 | 18 | [Test] 19 | public function providesConvenientShortcutForNotEqualTo():void 20 | { 21 | 22 | assertMatches("should match", not("A"), "B"); 23 | assertMatches("should match", not("B"), "A"); 24 | assertDoesNotMatch("should not match", not("A"), "A"); 25 | assertDoesNotMatch("should not match", not("B"), "B"); 26 | assertDescription("not \"A\"", not("A")); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/core/IsNothingTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.core 2 | { 3 | import org.hamcrest.*; 4 | 5 | public class IsNothingTest extends AbstractMatcherTestCase 6 | { 7 | [Test] 8 | public function always_evaluates_to_false():void 9 | { 10 | assertDoesNotMatch("null", nothing(), null); 11 | assertDoesNotMatch("Object", nothing(), {}); 12 | assertDoesNotMatch("Number", nothing(), 123); 13 | assertDoesNotMatch("Boolean", nothing(), true); 14 | assertDoesNotMatch("String", nothing(), "string"); 15 | } 16 | 17 | [Test] 18 | public function has_default_description():void 19 | { 20 | assertDescription("NOTHING", nothing()); 21 | } 22 | 23 | [Test] 24 | public function has_overrideable_description():void 25 | { 26 | var description:String = "description"; 27 | assertDescription(description, nothing(description)); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/date/DateAfterTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.date 2 | { 3 | 4 | import org.hamcrest.AbstractMatcherTestCase; 5 | 6 | public class DateAfterTest extends AbstractMatcherTestCase 7 | { 8 | 9 | [Test] 10 | public function comparesDatesUsingDateAfter():void 11 | { 12 | assertMatches("after", dateAfter(new Date(2000, 1, 1)), new Date(2002, 1, 1)); 13 | assertDoesNotMatch("not after", dateAfter(new Date(2000, 1, 1)), new Date(2000, 1, 1)); 14 | } 15 | 16 | [Test] 17 | public function comparesDatesUsingDateAfterOrEqualTo():void 18 | { 19 | assertMatches("after", dateAfterOrEqual(new Date(2000, 1, 1)), new Date(2000, 1, 1)); 20 | assertDoesNotMatch("not after", dateAfterOrEqual(new Date(2000, 1, 1)), new Date(1999, 1, 1)); 21 | } 22 | 23 | [Test] 24 | public function hasAReadableDescription():void 25 | { 26 | var expectedDate:Date = new Date(1980, 1, 1); 27 | 28 | assertDescription( 29 | "a date after " + describeDate(expectedDate), 30 | dateAfter(expectedDate)); 31 | 32 | assertDescription( 33 | "a date after or equal to " + describeDate(expectedDate), 34 | dateAfterOrEqual(new Date(1980, 1, 1))); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/date/DateBeforeTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.date 2 | { 3 | import org.hamcrest.AbstractMatcherTestCase; 4 | 5 | public class DateBeforeTest extends AbstractMatcherTestCase 6 | { 7 | [Test] 8 | public function comparesDateValuesUsingDateBefore():void 9 | { 10 | assertMatches("before", dateBefore(new Date(2000, 1, 1)), new Date(1999, 1, 1)); 11 | assertDoesNotMatch("not before", dateBefore(new Date(2000, 1, 1)), new Date(2011, 1, 1)); 12 | } 13 | 14 | [Test] 15 | public function comparesDateValuesUsingDateBeforeOrEqualTo():void 16 | { 17 | assertMatches("before", dateBeforeOrEqual(new Date(2000, 1, 1)), new Date(2000, 1, 1)); 18 | assertDoesNotMatch("not before", dateBeforeOrEqual(new Date(2000, 1, 1)), new Date(2011, 1, 1)); 19 | } 20 | 21 | [Test] 22 | public function hasAReadableDescription():void 23 | { 24 | var expectedDate:Date = new Date(1980, 1, 1); 25 | 26 | assertDescription( 27 | "a date before " + describeDate(expectedDate), 28 | dateBefore(expectedDate)); 29 | 30 | assertDescription( 31 | "a date before or equal to " + describeDate(expectedDate), 32 | dateBeforeOrEqual(expectedDate)); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/date/DateEqualTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.date 2 | { 3 | import org.hamcrest.AbstractMatcherTestCase; 4 | import org.hamcrest.StringDescription; 5 | 6 | public class DateEqualTest extends AbstractMatcherTestCase 7 | { 8 | [Test] 9 | public function compares_dates_using_millisecond_precision():void 10 | { 11 | assertMatches("equal", dateEqual(new Date(2002, 1, 1, 0, 0, 0, 1)), new Date(2002, 1, 1, 0, 0, 0, 1)); 12 | 13 | assertDoesNotMatch("not equal", dateEqual(new Date(2002, 1, 1, 0, 0, 1)), new Date(2002, 1, 1, 0, 0, 2)); 14 | } 15 | 16 | [Test] 17 | public function describes_the_expected_date_to_millisecond_precision():void 18 | { 19 | var expectedDate:Date = new Date(1980, 1, 1); 20 | 21 | assertDescription( 22 | "a date equal to " + describeDate(expectedDate), 23 | dateEqual(expectedDate)); 24 | } 25 | 26 | [Test] 27 | public function describes_the_mismatched_date_to_millisecond_precision():void 28 | { 29 | var expectedDate:Date = new Date(2002, 1, 1, 0, 0, 0, 1); 30 | var actualDate:Date = new Date(2002, 1, 1, 0, 0, 0, 2); 31 | 32 | assertMismatch( 33 | describeDate(actualDate) + " is not the same as " + describeDate(expectedDate), 34 | dateEqual(expectedDate), actualDate); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/date/describeDate.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.date 2 | { 3 | import org.hamcrest.StringDescription; 4 | 5 | public function describeDate(date:Date):String 6 | { 7 | return (new StringDescription().appendValue(date).toString()) 8 | } 9 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/filter/FilterFunctionTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.filter 2 | { 3 | import org.flexunit.Assert; 4 | 5 | import org.hamcrest.core.not; 6 | import org.hamcrest.text.containsString; 7 | import org.hamcrest.text.emptyString; 8 | 9 | public class FilterFunctionTest extends Assert 10 | { 11 | private var filterFunction:FilterFunction; 12 | 13 | [Before] 14 | public function setup():void 15 | { 16 | filterFunction = new FilterFunction(); 17 | } 18 | 19 | [Test] 20 | public function returnsTrueIfNoMatcher():void 21 | { 22 | filterFunction.matcher = null; 23 | 24 | assertTrue( filterFunction.filter( "test" ) ); 25 | } 26 | 27 | [Test] 28 | public function returnsTrueIfValueMatchesMatcher():void 29 | { 30 | filterFunction.matcher = not( emptyString() ); 31 | 32 | assertTrue( filterFunction.filter( "a non-empty string" ) ); 33 | } 34 | 35 | [Test] 36 | public function returnsFalseIfValueDoesNotMatchMatcher():void 37 | { 38 | filterFunction.matcher = not( containsString("expected") ); 39 | 40 | assertFalse( filterFunction.filter( "unexpected" ) ); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/mxml/AbstractMXMLMatcherTestCase.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml 2 | { 3 | import org.flexunit.Assert; 4 | 5 | public class AbstractMXMLMatcherTestCase extends Assert 6 | { 7 | public function assertMatched(message:String, matcher:MXMLMatcher):void 8 | { 9 | assertTrue(message, matcher.matched); 10 | } 11 | 12 | public function assertNotMatched(message:String, matcher:MXMLMatcher):void 13 | { 14 | assertFalse(message, matcher.matched); 15 | } 16 | 17 | public function assertDescription(expected:String, matcher:MXMLMatcher):void 18 | { 19 | assertEquals("Expected description", expected, matcher.description); 20 | } 21 | 22 | public function assertMatchedMismatchDescription(matcher:MXMLMatcher):void 23 | { 24 | assertTrue("Precondition: Matcher should be matched", matcher.matched); 25 | assertEquals("Expected mismatch description to be an empty string", "", matcher.mismatchDescription); 26 | } 27 | 28 | public function assertMismatchDescription(expected:String, matcher:MXMLMatcher):void 29 | { 30 | assertFalse("Precondition: Matcher should not be matched", matcher.matched); 31 | assertEquals("Expected mismatch description", expected, matcher.mismatchDescription); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/mxml/BaseMXMLMatcherCompositeTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml 2 | { 3 | import flash.events.Event; 4 | 5 | import mockolate.runner.MockolateRunner; MockolateRunner; 6 | import mockolate.stub; 7 | 8 | import org.flexunit.async.Async; 9 | import org.hamcrest.Matcher; 10 | import org.hamcrest.core.anything; 11 | 12 | [RunWith("mockolate.runner.MockolateRunner")] 13 | public class BaseMXMLMatcherCompositeTest 14 | { 15 | public var matcher:BaseMXMLMatcherComposite; 16 | 17 | [Mock] 18 | public var child:BaseMXMLMatcher; 19 | 20 | [Before] 21 | public function setup():void 22 | { 23 | matcher = new BaseMXMLMatcherCompositeForTesting(); 24 | matcher.matcher = child; 25 | } 26 | 27 | [Test(async)] 28 | public function shouldInvalidateItselfWhenChildMatchedPropertyChanges():void 29 | { 30 | stub(child).asEventDispatcher(); 31 | stub(child).method("matches").args(anything()).returns(true); 32 | 33 | Async.proceedOnEvent(this, matcher, "matchedChanged"); 34 | 35 | child.dispatchEvent(new Event("matchedChanged")); 36 | } 37 | } 38 | } 39 | 40 | import org.hamcrest.Matcher; 41 | import org.hamcrest.core.describedAs; 42 | import org.hamcrest.mxml.BaseMXMLMatcherComposite; 43 | 44 | internal class BaseMXMLMatcherCompositeForTesting extends BaseMXMLMatcherComposite 45 | { 46 | override protected function createMatcher():Matcher 47 | { 48 | return describedAs("BaseMXMLMatcherCompositeForTesting", matcher); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/mxml/BaseMXMLMatcherTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml 2 | { 3 | 4 | public class BaseMXMLMatcherTest extends AbstractMXMLMatcherTestCase 5 | { 6 | 7 | [Test] 8 | public function targetPropertyIsBindable():void 9 | { 10 | 11 | } 12 | 13 | [Test] 14 | public function matchedPropertyIsTrueWhenTargetMatches():void 15 | { 16 | 17 | } 18 | 19 | [Test] 20 | public function matchedPropertyIsFalseWhenTargetDoesNotMatch():void 21 | { 22 | 23 | } 24 | 25 | [Test] 26 | public function matchedPropertyIsBindable():void 27 | { 28 | 29 | } 30 | 31 | [Test] 32 | public function mismatchDescriptionPropertyIsBindable():void 33 | { 34 | 35 | } 36 | 37 | [Test] 38 | public function mismatchDescriptionIsNullWhenTargetMatches():void 39 | { 40 | 41 | 42 | } 43 | 44 | [Test] 45 | public function mismatchDescriptionHasDescriptionOfMatcherWhenTargetDoesNotMatch():void 46 | { 47 | 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/mxml/collection/EmptyArrayTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.collection 2 | { 3 | import org.hamcrest.mxml.AbstractMXMLMatcherTestCase; 4 | 5 | /* 6 | 7 | */ 8 | public class EmptyArrayTest extends AbstractMXMLMatcherTestCase 9 | { 10 | private var matcher:EmptyArray; 11 | 12 | [Before] 13 | public function createMatcher():void 14 | { 15 | matcher = new EmptyArray(); 16 | } 17 | 18 | [Test] 19 | public function hasDescription():void 20 | { 21 | assertDescription("an empty Array", matcher); 22 | } 23 | 24 | [Test] 25 | public function matchedIsTrueIfTargetMatches():void 26 | { 27 | matcher.target = []; 28 | 29 | assertMatched("matched if target matches", matcher); 30 | } 31 | 32 | [Test] 33 | public function matchedIsFalseIfTargetDoesNotMatch():void 34 | { 35 | matcher.target = [ 2, 3, 4 ]; 36 | 37 | assertNotMatched("not matched if target does not match", matcher); 38 | } 39 | 40 | [Test] 41 | public function mismatchDescriptionIsNullIfTargetMatches():void 42 | { 43 | matcher.target = []; 44 | 45 | assertMatchedMismatchDescription(matcher); 46 | } 47 | 48 | [Test] 49 | public function mismatchDescriptionIsSetIfTargetDoesNotMatch():void 50 | { 51 | matcher.target = [ 2, 3, 4 ]; 52 | 53 | assertMismatchDescription("was [<2>,<3>,<4>]", matcher); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/mxml/collection/InArrayTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.collection 2 | { 3 | import org.hamcrest.collection.InArrayMatcher; 4 | import org.hamcrest.mxml.AbstractMXMLMatcherTestCase; 5 | 6 | public class InArrayTest extends AbstractMXMLMatcherTestCase 7 | { 8 | private var matcher:InArray; 9 | 10 | [Before] 11 | public function createMatcher():void 12 | { 13 | matcher = new InArray(); 14 | matcher.elements = [ 1, 2, 3 ]; 15 | } 16 | 17 | [Test] 18 | public function hasDescription():void 19 | { 20 | assertDescription("contained in [<1>, <2>, <3>]", matcher); 21 | } 22 | 23 | [Test] 24 | public function matchedIsTrueIfTargetMatches():void 25 | { 26 | matcher.target = 2; 27 | assertMatched("matched if target matches", matcher); 28 | } 29 | 30 | [Test] 31 | public function matchedIsFalseIfTargetDoesNotMatch():void 32 | { 33 | matcher.target = 4; 34 | assertNotMatched("not matched if target does not match", matcher); 35 | } 36 | 37 | [Test] 38 | public function mismatchDescriptionIsNullIfTargetMatches():void 39 | { 40 | matcher.target = 2; 41 | assertMatchedMismatchDescription(matcher); 42 | } 43 | 44 | [Test] 45 | public function mismatchDescriptionIsSetIfTargetDoesNotMatch():void 46 | { 47 | matcher.target = 4; 48 | assertMismatchDescription("<4> was not contained in [<1>, <2>, <3>]", matcher); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/mxml/core/AnythingTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.core 2 | { 3 | import org.hamcrest.mxml.AbstractMXMLMatcherTestCase; 4 | 5 | /* 6 | 7 | */ 8 | public class AnythingTest extends AbstractMXMLMatcherTestCase 9 | { 10 | private var matcher:Anything; 11 | 12 | [Before] 13 | public function createMatcher():void 14 | { 15 | matcher = new Anything(); 16 | } 17 | 18 | [Test] 19 | public function hasDescription():void 20 | { 21 | assertDescription("ANYTHING", matcher); 22 | } 23 | 24 | [Test] 25 | public function matchedIsTrue():void 26 | { 27 | matcher.target = 4; 28 | 29 | assertMatched("matched if target matches", matcher); 30 | } 31 | 32 | [Test] 33 | public function mismatchDescriptionIsNullIfTargetMatches():void 34 | { 35 | matcher.target = 4; 36 | 37 | assertMatchedMismatchDescription(matcher); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/mxml/core/BaseMXMLMatcherTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.core 2 | { 3 | import org.hamcrest.mxml.AbstractMXMLMatcherTestCase; 4 | import org.hamcrest.mxml.BaseMXMLMatcher; 5 | import org.hamcrest.mxml.MXMLMatcher; 6 | 7 | public class BaseMXMLMatcherTest extends AbstractMXMLMatcherTestCase 8 | { 9 | 10 | [Test] 11 | public function targetPropertyIsBindable():void 12 | { 13 | 14 | } 15 | 16 | [Test] 17 | public function matchedPropertyIsTrueWhenTargetMatches():void 18 | { 19 | 20 | } 21 | 22 | [Test] 23 | public function matchedPropertyIsFalseWhenTargetDoesNotMatch():void 24 | { 25 | 26 | } 27 | 28 | [Test] 29 | public function matchedPropertyIsBindable():void 30 | { 31 | 32 | } 33 | 34 | [Test] 35 | public function mismatchDescriptionPropertyIsBindable():void 36 | { 37 | 38 | } 39 | 40 | [Test] 41 | public function mismatchDescriptionIsNullWhenTargetMatches():void 42 | { 43 | 44 | 45 | } 46 | 47 | [Test] 48 | public function mismatchDescriptionHasDescriptionOfMatcherWhenTargetDoesNotMatch():void 49 | { 50 | 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/mxml/number/GreaterThanTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.number 2 | { 3 | import org.hamcrest.mxml.AbstractMXMLMatcherTestCase; 4 | 5 | /* 6 | 7 | */ 8 | public class GreaterThanTest extends AbstractMXMLMatcherTestCase 9 | { 10 | private var matcher:GreaterThan; 11 | 12 | [Before] 13 | public function createMatcher():void 14 | { 15 | matcher = new GreaterThan(); 16 | matcher.value = 3; 17 | } 18 | 19 | [Test] 20 | public function hasDescription():void 21 | { 22 | assertDescription("a value greater than <3>", matcher); 23 | } 24 | 25 | [Test] 26 | public function matchedIsTrueIfTargetMatches():void 27 | { 28 | matcher.target = 4; 29 | 30 | assertMatched("matched if target matches", matcher); 31 | } 32 | 33 | [Test] 34 | public function matchedIsFalseIfTargetDoesNotMatch():void 35 | { 36 | matcher.target = 2; 37 | 38 | assertNotMatched("not matched if target does not match", matcher); 39 | } 40 | 41 | [Test] 42 | public function mismatchDescriptionIsNullIfTargetMatches():void 43 | { 44 | matcher.target = 4; 45 | 46 | assertMatchedMismatchDescription(matcher); 47 | } 48 | 49 | [Test] 50 | public function mismatchDescriptionIsSetIfTargetDoesNotMatch():void 51 | { 52 | matcher.target = 2; 53 | 54 | assertMismatchDescription("<2> was not greater than <3>", matcher); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/mxml/number/LessThanTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.number 2 | { 3 | import org.hamcrest.mxml.AbstractMXMLMatcherTestCase; 4 | 5 | /* 6 | 7 | */ 8 | public class LessThanTest extends AbstractMXMLMatcherTestCase 9 | { 10 | private var matcher:LessThan; 11 | 12 | [Before] 13 | public function createMatcher():void 14 | { 15 | matcher = new LessThan(); 16 | matcher.value = 3; 17 | } 18 | 19 | [Test] 20 | public function hasDescription():void 21 | { 22 | assertDescription("a value less than <3>", matcher); 23 | } 24 | 25 | [Test] 26 | public function matchedIsTrueIfTargetMatches():void 27 | { 28 | matcher.target = 2; 29 | 30 | assertMatched("matched if target matches", matcher); 31 | } 32 | 33 | [Test] 34 | public function matchedIsFalseIfTargetDoesNotMatch():void 35 | { 36 | matcher.target = 4; 37 | 38 | assertNotMatched("not matched if target does not match", matcher); 39 | } 40 | 41 | [Test] 42 | public function mismatchDescriptionIsNullIfTargetMatches():void 43 | { 44 | matcher.target = 2; 45 | 46 | assertMatchedMismatchDescription(matcher); 47 | } 48 | 49 | [Test] 50 | public function mismatchDescriptionIsSetIfTargetDoesNotMatch():void 51 | { 52 | matcher.target = 4; 53 | 54 | assertMismatchDescription("<4> was not less than <3>", matcher); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/mxml/object/EqualToTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.object 2 | { 3 | import org.hamcrest.mxml.AbstractMXMLMatcherTestCase; 4 | 5 | /* 6 | 7 | */ 8 | public class EqualToTest extends AbstractMXMLMatcherTestCase 9 | { 10 | private var matcher:EqualTo; 11 | 12 | [Before] 13 | public function createMatcher():void 14 | { 15 | matcher = new EqualTo(); 16 | matcher.value = 3; 17 | } 18 | 19 | [Test] 20 | public function hasDescription():void 21 | { 22 | assertDescription("<3>", matcher); 23 | } 24 | 25 | [Test] 26 | public function matchedIsTrueIfTargetMatches():void 27 | { 28 | matcher.target = 3; 29 | 30 | assertMatched("", matcher); 31 | } 32 | 33 | [Test] 34 | public function matchedIsFalseIfTargetDoesNotMatch():void 35 | { 36 | matcher.target = 4; 37 | 38 | assertNotMatched("", matcher); 39 | } 40 | 41 | [Test] 42 | public function mismatchDescriptionIsNullIfTargetMatches():void 43 | { 44 | matcher.target = 3; 45 | 46 | assertMatchedMismatchDescription(matcher); 47 | } 48 | 49 | [Test] 50 | public function mismatchDescriptionIsSetIfTargetDoesNotMatch():void 51 | { 52 | matcher.target = 4; 53 | 54 | assertMismatchDescription("was <4>", matcher); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/mxml/object/IsFalseTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.object 2 | { 3 | import org.hamcrest.mxml.AbstractMXMLMatcherTestCase; 4 | 5 | public class IsFalseTest extends AbstractMXMLMatcherTestCase 6 | { 7 | private var matcher:IsFalse; 8 | 9 | [Before] 10 | public function createMatcher():void 11 | { 12 | matcher = new IsFalse(); 13 | } 14 | 15 | [Test] 16 | public function hasDescription():void 17 | { 18 | assertDescription("is false", matcher); 19 | } 20 | 21 | [Test] 22 | public function matchedIsFalseIfTargetMatches():void 23 | { 24 | matcher.target = false; 25 | 26 | assertMatched("should match false", matcher); 27 | } 28 | 29 | [Test] 30 | public function matchedIsFalseIfTargetDoesNotMatch():void 31 | { 32 | matcher.target = true; 33 | 34 | assertNotMatched("should not match true", matcher); 35 | } 36 | 37 | [Test] 38 | public function mismatchDescriptionIsNullIfTargetMatched():void 39 | { 40 | matcher.target = false; 41 | 42 | assertMatchedMismatchDescription(matcher); 43 | } 44 | 45 | [Test] 46 | public function mismatchDescriptionIsSetIfTargetDoesNotMatch():void 47 | { 48 | matcher.target = true; 49 | 50 | assertMismatchDescription("was ", matcher); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/mxml/object/IsTrueTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.object 2 | { 3 | import org.hamcrest.mxml.AbstractMXMLMatcherTestCase; 4 | 5 | public class IsTrueTest extends AbstractMXMLMatcherTestCase 6 | { 7 | private var matcher:IsTrue; 8 | 9 | [Before] 10 | public function createMatcher():void 11 | { 12 | matcher = new IsTrue(); 13 | } 14 | 15 | [Test] 16 | public function hasDescription():void 17 | { 18 | assertDescription("is true", matcher); 19 | } 20 | 21 | [Test] 22 | public function matchedIsTrueIfTargetMatches():void 23 | { 24 | matcher.target = true; 25 | 26 | assertMatched("should match true", matcher); 27 | } 28 | 29 | [Test] 30 | public function matchedIsFalseIfTargetDoesNotMatch():void 31 | { 32 | matcher.target = false; 33 | 34 | assertNotMatched("should not match false", matcher); 35 | } 36 | 37 | [Test] 38 | public function mismatchDescriptionIsNullIfTargetMatched():void 39 | { 40 | matcher.target = true; 41 | 42 | assertMatchedMismatchDescription(matcher); 43 | } 44 | 45 | [Test] 46 | public function mismatchDescriptionIsSetIfTargetDoesNotMatch():void 47 | { 48 | matcher.target = false; 49 | 50 | assertMismatchDescription("was ", matcher); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/mxml/object/NotNullTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.object 2 | { 3 | import org.hamcrest.mxml.AbstractMXMLMatcherTestCase; 4 | import org.hamcrest.mxml.number.Between; 5 | 6 | /* 7 | 8 | */ 9 | public class NotNullTest extends AbstractMXMLMatcherTestCase 10 | { 11 | private var matcher:NotNull; 12 | 13 | [Before] 14 | public function createMatcher():void 15 | { 16 | matcher = new NotNull(); 17 | } 18 | 19 | [Test] 20 | public function hasDescription():void 21 | { 22 | assertDescription("not null", matcher); 23 | } 24 | 25 | [Test] 26 | public function matchedIsTrueIfTargetMatches():void 27 | { 28 | matcher.target = 9; 29 | 30 | assertMatched("matched if target matches", matcher); 31 | } 32 | 33 | [Test] 34 | public function matchedIsFalseIfTargetDoesNotMatch():void 35 | { 36 | matcher.target = null; 37 | 38 | assertNotMatched("not matched if target does not match", matcher); 39 | } 40 | 41 | [Test] 42 | public function mismatchDescriptionIsNullIfTargetMatches():void 43 | { 44 | matcher.target = 9; 45 | 46 | assertMatchedMismatchDescription(matcher); 47 | } 48 | 49 | [Test] 50 | public function mismatchDescriptionIsSetIfTargetDoesNotMatch():void 51 | { 52 | matcher.target = null; 53 | 54 | assertMismatchDescription("was null", matcher); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/mxml/object/NullTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.object 2 | { 3 | import org.hamcrest.mxml.AbstractMXMLMatcherTestCase; 4 | import org.hamcrest.mxml.number.Between; 5 | 6 | /* 7 | 8 | */ 9 | public class NullTest extends AbstractMXMLMatcherTestCase 10 | { 11 | private var matcher:Null; 12 | 13 | [Before] 14 | public function createMatcher():void 15 | { 16 | matcher = new Null(); 17 | } 18 | 19 | [Test] 20 | public function hasDescription():void 21 | { 22 | assertDescription("null", matcher); 23 | } 24 | 25 | [Test] 26 | public function matchedIsTrueIfTargetMatches():void 27 | { 28 | matcher.target = null; 29 | 30 | assertMatched("matched if target matches", matcher); 31 | } 32 | 33 | [Test] 34 | public function matchedIsFalseIfTargetDoesNotMatch():void 35 | { 36 | matcher.target = "anything"; 37 | 38 | assertNotMatched("not matched if target does not match", matcher); 39 | } 40 | 41 | [Test] 42 | public function mismatchDescriptionIsNullIfTargetMatches():void 43 | { 44 | matcher.target = null; 45 | 46 | assertMatchedMismatchDescription(matcher); 47 | } 48 | 49 | [Test] 50 | public function mismatchDescriptionIsSetIfTargetDoesNotMatch():void 51 | { 52 | matcher.target = "anything"; 53 | 54 | assertMismatchDescription('was "anything"', matcher); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/number/AtLeastTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.number 2 | { 3 | 4 | import org.hamcrest.AbstractMatcherTestCase; 5 | 6 | public class AtLeastTest extends AbstractMatcherTestCase 7 | { 8 | [Test] 9 | public function comparesValuesUsingAtLeast():void 10 | { 11 | assertMatches("greater than", atLeast(10), 10); 12 | assertDoesNotMatch("not greater than", atLeast(10), 9); 13 | } 14 | 15 | [Test] 16 | public function hasAReadableDescription():void 17 | { 18 | assertDescription("at least <3>", atLeast(3)); 19 | } 20 | 21 | [Test] 22 | public function hasMismatchDescription():void 23 | { 24 | assertMismatch("was <2>", atLeast(3), 2); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/number/AtMostTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.number 2 | { 3 | import org.hamcrest.AbstractMatcherTestCase; 4 | 5 | public class AtMostTest extends AbstractMatcherTestCase 6 | { 7 | [Test] 8 | public function comparesValuesUsingAtMost():void 9 | { 10 | assertMatches("less than", atMost(10), 10); 11 | assertDoesNotMatch("not less than", atMost(10), 11); 12 | } 13 | 14 | [Test] 15 | public function hasAReadableDescription():void 16 | { 17 | assertDescription("at most <3>", atMost(3)); 18 | } 19 | 20 | [Test] 21 | public function hasMismatchDescription():void 22 | { 23 | assertMismatch("was <4>", atMost(3), 4); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/number/BetweenTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.number 2 | { 3 | import org.hamcrest.AbstractMatcherTestCase; 4 | import org.hamcrest.Matcher; 5 | 6 | public class BetweenTest extends AbstractMatcherTestCase 7 | { 8 | [Test] 9 | public function betweenInclusive():void 10 | { 11 | assertMatches("inside range", between(2, 4), 3); 12 | assertDoesNotMatch("outside range", between(2, 3), 4); 13 | } 14 | 15 | [Test] 16 | public function betweenExclusive():void 17 | { 18 | assertMatches("inside range", between(2, 4, true), 3); 19 | assertDoesNotMatch("outside range", between(2, 3, true), 3); 20 | } 21 | 22 | [Test] 23 | public function hasAReadableDescription():void 24 | { 25 | assertDescription("a Number between <2> and <4>", between(2, 4)); 26 | assertDescription("a Number between <2> and <4> exclusive", between(2, 4, true)); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/number/GreaterThanTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.number 2 | { 3 | 4 | import org.hamcrest.AbstractMatcherTestCase; 5 | 6 | public class GreaterThanTest extends AbstractMatcherTestCase 7 | { 8 | 9 | [Test] 10 | public function comparesValuesUsingGreaterThan():void 11 | { 12 | assertMatches("greater than", greaterThan(10), 11); 13 | assertDoesNotMatch("not greater than", greaterThan(10), 10); 14 | } 15 | 16 | [Test] 17 | public function comparesValuesUsingGreaterThanOrEqualTo():void 18 | { 19 | assertMatches("greater than", greaterThanOrEqualTo(10), 10); 20 | assertDoesNotMatch("not greater than", greaterThanOrEqualTo(10), 9); 21 | } 22 | 23 | [Test] 24 | public function hasAReadableDescription():void 25 | { 26 | assertDescription("a value greater than <3>", greaterThan(3)); 27 | assertDescription("a value greater than or equal to <3>", greaterThanOrEqualTo(3)); 28 | } 29 | 30 | [Test] 31 | public function hasMismatchDescription():void 32 | { 33 | assertMismatch("<3> was not greater than <3>", greaterThan(3), 3); 34 | } 35 | 36 | [Test] 37 | public function hasMismatchDescriptionIfNotEqualTo():void 38 | { 39 | assertMismatch("<2> was not greater than or equal to <3>", greaterThanOrEqualTo(3), 2); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/number/IsNotANumberTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.number 2 | { 3 | import org.hamcrest.AbstractMatcherTestCase; 4 | 5 | public class IsNotANumberTest extends AbstractMatcherTestCase 6 | { 7 | [Test] 8 | public function shouldMatchNaN():void 9 | { 10 | assertMatches("should match NaN", isNotANumber(), NaN); 11 | } 12 | 13 | [Test] 14 | public function shouldNotMatchNumber():void 15 | { 16 | assertDoesNotMatch("should not match 0", isNotANumber(), 0); 17 | assertDoesNotMatch("should not match positive number", isNotANumber(), 1); 18 | assertDoesNotMatch("should not match negative number", isNotANumber(), -1); 19 | assertDoesNotMatch("should not match positive infinity", isNotANumber(), Number.POSITIVE_INFINITY); 20 | assertDoesNotMatch("should not match negative infinity", isNotANumber(), Number.NEGATIVE_INFINITY); 21 | } 22 | 23 | [Test] 24 | public function shouldHaveAReadableDescription():void 25 | { 26 | assertDescription("NaN", isNotANumber()); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/number/IsNumberTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.number 2 | { 3 | import org.hamcrest.AbstractMatcherTestCase; 4 | 5 | public class IsNumberTest extends AbstractMatcherTestCase 6 | { 7 | [Test] 8 | public function shouldMatchNumber():void 9 | { 10 | assertMatches("should match 0", isNumber(), 0); 11 | assertMatches("should match positive number", isNumber(), 1); 12 | assertMatches("should match negative number", isNumber(), -1); 13 | assertMatches("should match maximum number", isNumber(), Number.MAX_VALUE); 14 | assertMatches("should match minimum number", isNumber(), Number.MIN_VALUE); 15 | } 16 | 17 | [Test] 18 | public function shouldNotMatchNaN():void 19 | { 20 | assertDoesNotMatch("should not match NaN", isNumber(), NaN); 21 | } 22 | 23 | [Test] 24 | public function shouldNotMatchInfinity():void 25 | { 26 | assertDoesNotMatch("should not match positive infinity", isNumber(), Number.POSITIVE_INFINITY); 27 | assertDoesNotMatch("should not match negative infinity", isNumber(), Number.NEGATIVE_INFINITY); 28 | } 29 | 30 | [Test] 31 | public function shouldNotMatchNonNumber():void 32 | { 33 | assertDoesNotMatch("should not match `true`", isNumber(), true); 34 | assertDoesNotMatch("should not match `false`", isNumber(), false); 35 | assertDoesNotMatch("should not match Object", isNumber(), {}); 36 | assertDoesNotMatch("should not match Class", isNumber(), Number); 37 | } 38 | 39 | [Test] 40 | public function shouldHaveAReadableDescription():void 41 | { 42 | assertDescription("a Number", isNumber()); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/number/LessThanTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.number 2 | { 3 | 4 | import org.hamcrest.AbstractMatcherTestCase; 5 | 6 | public class LessThanTest extends AbstractMatcherTestCase 7 | { 8 | 9 | [Test] 10 | public function comparesValuesUsingLessThan():void 11 | { 12 | assertMatches("less than", lessThan(10), 9); 13 | assertDoesNotMatch("not less than", lessThan(10), 11); 14 | } 15 | 16 | [Test] 17 | public function comparesValuesUsingLessThanOrEqualTo():void 18 | { 19 | assertMatches("less than", lessThanOrEqualTo(10), 10); 20 | assertDoesNotMatch("not less than", lessThanOrEqualTo(10), 11); 21 | } 22 | 23 | [Test] 24 | public function hasAReadableDescription():void 25 | { 26 | assertDescription("a value less than <3>", lessThan(3)); 27 | assertDescription("a value less than or equal to <3>", lessThanOrEqualTo(3)); 28 | } 29 | 30 | [Test] 31 | public function hasMismatchDescription():void 32 | { 33 | assertMismatch("<3> was not less than <3>", lessThan(3), 3); 34 | } 35 | 36 | [Test] 37 | public function hasMismatchDescriptionIfNotEqualTo():void 38 | { 39 | assertMismatch("<4> was not less than or equal to <3>", lessThanOrEqualTo(3), 4); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/object/IsFalseTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.MatcherAssertTest; 4 | 5 | public class IsFalseTest extends MatcherAssertTest 6 | { 7 | [Test] 8 | public function matchesFalseValue():void 9 | { 10 | assertMatches("should match false", isFalse(), false); 11 | } 12 | 13 | [Test] 14 | public function matchesFalseyValue():void 15 | { 16 | assertMatches("should match false", isFalsey(), false); 17 | assertMatches("should match null", isFalsey(), null); 18 | assertMatches("should match 0", isFalsey(), 0); 19 | assertMatches("should match NaN", isFalsey(), NaN); 20 | } 21 | 22 | [Test] 23 | public function doesNotMatchTruthyValue():void 24 | { 25 | assertDoesNotMatch("should not match true", isFalse(), true); 26 | assertDoesNotMatch("should not match object", isFalse(), {}); 27 | assertDoesNotMatch("should not match non-zero-length string", isFalse(), " "); 28 | assertDoesNotMatch("should not match true", isFalsey(), true); 29 | assertDoesNotMatch("should not match object", isFalsey(), {}); 30 | assertDoesNotMatch("should not match non-zero-length string", isFalsey(), " "); 31 | } 32 | 33 | [Test] 34 | public function hasAReadableDescription():void 35 | { 36 | assertDescription("is false", isFalse()); 37 | assertDescription("is false", isFalsey()); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/object/IsInstanceOfTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | 4 | import org.hamcrest.*; 5 | import org.hamcrest.core.not; 6 | 7 | public class IsInstanceOfTest extends AbstractMatcherTestCase 8 | { 9 | 10 | [Test] 11 | public function evaluatesToTrueIfArgumentIsInstanceOfASpecificClass():void 12 | { 13 | 14 | assertThat(1, instanceOf(Number)); 15 | assertThat(1.0, instanceOf(Number)); 16 | 17 | assertThat(null, not(instanceOf(Number))); 18 | assertThat("hello", not(instanceOf(Number))); 19 | } 20 | 21 | [Test] 22 | public function hasAReadableDescription():void 23 | { 24 | assertDescription("an instance of Number", instanceOf(Number)); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/object/IsInterfaceTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.AbstractMatcherTestCase; 4 | import org.hamcrest.test.support.ExampleClass; 5 | import org.hamcrest.test.support.ExampleInterface; 6 | 7 | public class IsInterfaceTest extends AbstractMatcherTestCase 8 | { 9 | [Test] 10 | public function should_match_interface():void 11 | { 12 | assertMatches("interface", 13 | isInterface(), ExampleInterface); 14 | } 15 | 16 | [Test] 17 | public function should_not_match_class():void 18 | { 19 | assertDoesNotMatch("class", 20 | isInterface(), ExampleClass); 21 | } 22 | 23 | [Test] 24 | public function describes_matcher():void 25 | { 26 | assertDescription("an interface", 27 | isInterface()); 28 | } 29 | 30 | [Test] 31 | public function describes_mismatch():void 32 | { 33 | assertMismatch("was <[class ExampleClass]>", 34 | isInterface(), ExampleClass); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/object/IsNotNullTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.*; 4 | import org.hamcrest.core.not; 5 | 6 | public class IsNotNullTest extends AbstractMatcherTestCase 7 | { 8 | [Test] 9 | public function evaluatesToTrueIfArgumentIsNotNull():void 10 | { 11 | assertThat("not null", not(nullValue())); 12 | assertThat("not null", notNullValue()); 13 | } 14 | 15 | [Test] 16 | public function isNotNull_matchingNull_shouldBeFalse():void 17 | { 18 | assertDoesNotMatch("null should match", isNotNull(), null); 19 | } 20 | 21 | [Test] 22 | public function isNotNull_matchingUndefined_shouldBeFalse():void 23 | { 24 | assertDoesNotMatch("undefined should not match", isNotNull(), undefined); 25 | } 26 | 27 | [Test] 28 | public function isNotNull_matchingObject_shouldBeTrue():void 29 | { 30 | assertMatches("Object should not match", isNotNull(), {}); 31 | } 32 | 33 | [Test] 34 | public function isNotNull_matchingArray_shouldBeTrue():void 35 | { 36 | assertMatches("Array", isNotNull(), []); 37 | } 38 | 39 | [Test] 40 | public function isNotNull_matchingBoolean_shouldBeTrue():void 41 | { 42 | assertMatches("Boolean should not match", isNotNull(), true); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/object/IsNullTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.*; 4 | import org.hamcrest.core.not; 5 | 6 | public class IsNullTest extends AbstractMatcherTestCase 7 | { 8 | [Test] 9 | public function evaluatesToTrueIfArgumentIsNull():void 10 | { 11 | assertThat(null, nullValue()); 12 | assertThat("not null", not(nullValue())); 13 | 14 | assertThat("not null", notNullValue()); 15 | assertThat(null, not(notNullValue())); 16 | } 17 | 18 | [Test] 19 | public function isNull_matchingNull_shouldBeTrue():void 20 | { 21 | assertMatches("null should match", isNull(), null); 22 | } 23 | 24 | [Test] 25 | public function isNull_matchingUndefined_shouldBeTrue_asCoercionRulesConvertUndefinedToNull():void 26 | { 27 | assertMatches("undefined should match", isNull(), undefined); 28 | } 29 | 30 | [Test] 31 | public function isNull_matchingObject_shouldBeFalse():void 32 | { 33 | assertDoesNotMatch("Object should not match", isNull(), {}); 34 | } 35 | 36 | [Test] 37 | public function isNull_matchingArray_shouldBeFalse():void 38 | { 39 | assertDoesNotMatch("Array", isNull(), []); 40 | } 41 | 42 | [Test] 43 | public function isNull_matchingBoolean_shouldBeFalse():void 44 | { 45 | assertDoesNotMatch("Boolean should not match", isNull(), true); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/object/IsSameTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | 4 | import org.hamcrest.*; 5 | import org.hamcrest.core.not; 6 | 7 | public class IsSameTest extends AbstractMatcherTestCase 8 | { 9 | 10 | [Test] 11 | public function evaluatesToTrueIfArgumentIsReferenceToASpecificObject():void 12 | { 13 | var o1:Object = {}; 14 | var o2:Object = {}; 15 | 16 | assertThat(o1, sameInstance(o1)); 17 | assertThat(o2, not(sameInstance(o1))); 18 | } 19 | 20 | [Test] 21 | public function returnsReadableDescriptionFromToString():void 22 | { 23 | assertDescription("same instance \"ARG\"", sameInstance("ARG")); 24 | } 25 | 26 | [Test] 27 | public function returnsReadableDescriptionFromToStringWhenInitializedithNull():void 28 | { 29 | assertDescription("same instance null", sameInstance(null)); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/object/IsStrictlyEqualTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | 4 | import org.hamcrest.*; 5 | import org.hamcrest.core.not; 6 | 7 | public class IsStrictlyEqualTest extends AbstractMatcherTestCase 8 | { 9 | 10 | [Test] 11 | public function matchesStrictly():void 12 | { 13 | var o1:Object = {}; 14 | var o2:Object = {}; 15 | 16 | assertMatches("should match with ===", strictlyEqualTo(o1), o1); 17 | assertDoesNotMatch("should match with ===", strictlyEqualTo(o1), o2); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/object/IsTrueTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.MatcherAssertTest; 4 | 5 | public class IsTrueTest extends MatcherAssertTest 6 | { 7 | [Test] 8 | public function matchesTrueValue():void 9 | { 10 | assertMatches("should match true", isTrue(), true); 11 | } 12 | 13 | [Test] 14 | public function matchesTruthyValue():void 15 | { 16 | assertMatches("should match true", isTruthy(), true); 17 | assertMatches("should match object", isTruthy(), {}); 18 | assertMatches("should match non-zero-length string", isTruthy(), " "); 19 | } 20 | 21 | [Test] 22 | public function doesNotMatchFalseyValue():void 23 | { 24 | assertDoesNotMatch("should not match false", isTrue(), false); 25 | assertDoesNotMatch("should not match null", isTrue(), null); 26 | assertDoesNotMatch("should not match 0", isTrue(), 0); 27 | assertDoesNotMatch("should not match NaN", isTrue(), NaN); 28 | assertDoesNotMatch("should not match false", isTruthy(), false); 29 | assertDoesNotMatch("should not match null", isTruthy(), null); 30 | assertDoesNotMatch("should not match 0", isTruthy(), 0); 31 | assertDoesNotMatch("should not match NaN", isTruthy(), NaN); 32 | } 33 | 34 | [Test] 35 | public function hasAReadableDescription():void 36 | { 37 | assertDescription("is true", isTrue()); 38 | assertDescription("is true", isTruthy()); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/object/NullOrMatcherTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.AbstractMatcherTestCase; 4 | import org.hamcrest.Matcher; 5 | import org.hamcrest.assertThat; 6 | import org.hamcrest.number.greaterThan; 7 | import org.hamcrest.text.emptyString; 8 | 9 | public class NullOrMatcherTest extends AbstractMatcherTestCase 10 | { 11 | private var matcher:Matcher; 12 | 13 | [Before] 14 | public function withMatcher():void 15 | { 16 | matcher = nullOr(greaterThan(0)); 17 | } 18 | 19 | [Test] 20 | public function nullOr_with_null_matches():void 21 | { 22 | assertMatches("with null", matcher, null); 23 | assertMatches("with matching value", matcher, 1); 24 | assertDoesNotMatch("with non-matching value", matcher, 0); 25 | } 26 | 27 | [Test] 28 | public function describes_matcher():void 29 | { 30 | assertDescription("(null or a value greater than <0>)", matcher); 31 | } 32 | 33 | [Test] 34 | public function describes_mismatch():void 35 | { 36 | assertMismatch("was <0>", matcher, 0); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/test/support/ExampleClass.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.test.support 2 | { 3 | public class ExampleClass 4 | { 5 | public function ExampleClass() 6 | { 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/test/support/ExampleInterface.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.test.support 2 | { 3 | public interface ExampleInterface 4 | { 5 | 6 | } 7 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/test/support/ExtendedExampleInterface.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.test.support 2 | { 3 | public interface ExtendedExampleInterface extends ExampleInterface 4 | { 5 | 6 | } 7 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/test/support/ImplementingExampleClass.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.test.support 2 | { 3 | public class ImplementingExampleClass implements ExampleInterface 4 | { 5 | public function ImplementingExampleClass() 6 | { 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /hamcrest-unit-test/src/org/hamcrest/text/ContainsStringsTest.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.text 2 | { 3 | import org.hamcrest.AbstractMatcherTestCase; 4 | 5 | public class ContainsStringsTest extends AbstractMatcherTestCase 6 | { 7 | [Test] 8 | public function matches_withArrayOfStrings():void 9 | { 10 | assertMatches("contains all", containsStrings(["a", "lazy", "fox"]), "a quick brown fox jumps over the lazy dog"); 11 | assertDoesNotMatch("contains none", containsStrings(["a", "lazy", "fox"]), "pack my box with five dozen liquor jugs"); 12 | } 13 | 14 | [Test] 15 | public function matches_withParametersOfStrings():void 16 | { 17 | assertMatches("contains all", containsStrings("a", "lazy", "fox"), "a quick brown fox jumps over the lazy dog"); 18 | assertDoesNotMatch("contains none", containsStrings("a", "lazy", "fox"), "pack my box with five dozen liquor jugs"); 19 | } 20 | 21 | [Test] 22 | public function describesItself():void 23 | { 24 | assertDescription('a String containing all of ["a","lazy","fox"]', containsStrings("a", "lazy", "fox")); 25 | } 26 | 27 | [Test] 28 | public function describesMismatches():void 29 | { 30 | assertMismatch('was "Jump by vow of quick, lazy strength in Oxford." did not contain ["fox","dog"]', 31 | containsStrings("a", "lazy", "fox", "dog"), 32 | "Jump by vow of quick, lazy strength in Oxford."); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /hamcrest/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | hamcrest 4 | 5 | 6 | 7 | 8 | 9 | com.adobe.flexbuilder.project.flexbuilder 10 | 11 | 12 | 13 | 14 | 15 | com.adobe.flexbuilder.project.flexlibnature 16 | com.adobe.flexbuilder.project.actionscriptnature 17 | 18 | 19 | -------------------------------------------------------------------------------- /hamcrest/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 the original author or authors 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | Redistributions in binary form must reproduce the above copyright notice, this list of 11 | conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | Neither the name of the Hamcrest nor the names of its contributors may be used to 15 | endorse or promote products derived from this software without specific prior 16 | written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 21 | SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 23 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 24 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 26 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /hamcrest/build-docs.sh: -------------------------------------------------------------------------------- 1 | asdoc \ 2 | -output docs \ 3 | -doc-sources src \ 4 | -lenient \ 5 | -compiler.debug=true \ 6 | -warnings=true \ 7 | -main-title "Hamcrest AS3 API Documentation" \ 8 | -window-title "Hamcrest AS3 API Documentation" 9 | -------------------------------------------------------------------------------- /hamcrest/build-swc.sh: -------------------------------------------------------------------------------- 1 | # swc 2 | compc \ 3 | -source-path src \ 4 | -include-sources src \ 5 | -namespace http://hamcrest.org/2009/mxml src/hamcrest-manifest.xml \ 6 | -output bin/hamcrest-1.1.0.swc -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/collection/everyByMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.collection 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Executes a Matcher on each item in the array until an item is reached that returns false for the specified 7 | * matcher. You use this method to determine whether all items in an array meet a criterion, such as having 8 | * values less than a particular number. 9 | * 10 | * @param arrayLike Array or Object iterable with a for-each-loop. 11 | * @param elementMatcher Matcher the items must match. 12 | * @return A Boolean value of true if all items in the array return true for the specified matcher; 13 | * otherwise, false. 14 | * 15 | * @see org.hamcrest.collection#someByMatcher() 16 | * 17 | * @example 18 | * 19 | * var items:Array = [{ value: 1 }, { value: 22 }, { value: 33 }]; 20 | * var allItemsValid:Boolean = everyByMatcher(items, hasProperties({ value: lessThan(50) })); 21 | * if (allItemsValid) { 22 | * // ... 23 | * } 24 | * 25 | */ 26 | public function everyByMatcher(arrayLike:Object, elementMatcher:Matcher):Boolean 27 | { 28 | for each (var item:* in arrayLike) 29 | { 30 | if (! elementMatcher.matches(item)) 31 | { 32 | return false; 33 | } 34 | } 35 | 36 | return true; 37 | } 38 | } -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/collection/filterByMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.collection 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Executes a Matcher on each item in the array and constructs a new array for all items that return true for the 7 | * specified matcher. If an item returns false, it is not included in the new array. 8 | * 9 | * @param arrayLike Array or Object with a 'length' property and iterable with a for-loop. 10 | * @param elementMatcher Matcher the item must match. 11 | * @returns A new array that contains all items from the original array that returned true. 12 | * 13 | * @example 14 | * 15 | * var items:Array = [{ value: 5 }, { value: 10 }, { value: 15 }, { value: 3 }]; 16 | * var matching:Array = filterByMatcher(items, hasProperties({ value: greaterThan(5) })); 17 | * // matching === [items[1], items[2]] 18 | * 19 | */ 20 | public function filterByMatcher(arrayLike:Object, elementMatcher:Matcher):Array 21 | { 22 | const matching:Array = []; 23 | 24 | for each (var item:* in arrayLike) 25 | { 26 | if (elementMatcher.matches(item)) 27 | { 28 | matching[matching.length] = item; 29 | } 30 | } 31 | 32 | return matching; 33 | } 34 | } -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/collection/indexOfByMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.collection 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Searches for an item in an array-like object by using a Matcher and returns the index position of the item. 7 | * 8 | * @param arrayLike Array or Object with a 'length' property and iterable with a for-loop. 9 | * @param elementMatcher Matcher the item must match. 10 | * @param startIndex The location in the arrayLike from which to start searching for the item. 11 | * @returns A zero-based index position of the item in the array. 12 | * If the searchElement argument is not found, the return value is -1. 13 | * 14 | * @example 15 | * 16 | * var items:Array = [{ value: 1 }, { value: 5 }, { value: 11 }]; 17 | * var index:int = indexOfByMatcher(items, hasProperties({ value: 5 })); 18 | * // index === 1 19 | * 20 | */ 21 | public function indexOfByMatcher(arrayLike:Object, elementMatcher:Matcher, startIndex:int = 0):int 22 | { 23 | for (var i:int = startIndex, n:int = arrayLike.length; i < n; i++) 24 | { 25 | var item:* = arrayLike[i]; 26 | 27 | if (elementMatcher.matches(item)) 28 | { 29 | return i; 30 | } 31 | } 32 | 33 | return -1; 34 | } 35 | } -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/collection/indexesOfByMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.collection 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Searches for an item in an array-like object by using a Matcher and returns the index positions of all matching items. 7 | * 8 | * @param arrayLike Array or Object with a 'length' property and iterable with a for-loop. 9 | * @param elementMatcher Matcher the item must match. 10 | * @param startIndex The location in the arrayLike from which to start searching for the item. 11 | * @return Array of index positions of matching items. 12 | * 13 | * @example 14 | * 15 | * var items:Array = [{ value: 5 }, { value: 10 }, { id: 5 }]; 16 | * var indexes:Array = indexOfByMatcher(items, hasProperties({ value: lessThan(10) })); 17 | * // indexes === [0, 2] 18 | * 19 | */ 20 | public function indexesOfByMatcher(arrayLike:Object, elementMatcher:Matcher, startIndex:int = 0):Array 21 | { 22 | var indexes:Array = []; 23 | 24 | for (var i:int = startIndex, n:int = arrayLike.length; i < n; i++) 25 | { 26 | var item:* = arrayLike[i]; 27 | 28 | if (elementMatcher.matches(item)) 29 | { 30 | indexes[indexes.length] = i; 31 | } 32 | } 33 | 34 | return indexes; 35 | } 36 | } -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/collection/rejectByMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.collection 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Executes a Matcher on each item in the array and constructs a new array for all items that return false for the 7 | * specified matcher. If an item returns true, it is not included in the new array. 8 | * 9 | * @param arrayLike Array or Object with a 'length' property and iterable with a for-loop. 10 | * @param elementMatcher Matcher the item must not match. 11 | * @return A new array that contains all items from the original array that returned false. 12 | * 13 | * @example 14 | * 15 | * var items:Array = [{ value: 5 }, { value: 10 }, { value: 15 }, { value: 3 }]; 16 | * var matching:Array = rejectByMatcher(items, hasProperties({ value: greaterThan(5) })); 17 | * // matching === [items[0], items[3]] 18 | * 19 | */ 20 | public function rejectByMatcher(arrayLike:Object, elementMatcher:Matcher):Array 21 | { 22 | const mismatched:Array = []; 23 | 24 | for each (var item:* in arrayLike) 25 | { 26 | if (!elementMatcher.matches(item)) 27 | { 28 | mismatched[mismatched.length] = item; 29 | } 30 | } 31 | 32 | return mismatched; 33 | } 34 | } -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/collection/someByMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.collection 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Executes a Matcher on each item in the array until an item is reached that returns true. Use this method to 7 | * determine whether any items in an array meet a criterion, such as having a value less than a particular number. 8 | * 9 | * @param arrayLike Array or Object iterable with a for-each-loop. 10 | * @param elementMatcher Matcher an item must match. 11 | * @return A Boolean value of true if any items in the array return true for the Matcher; 12 | * otherwise false. 13 | * 14 | * @see org.hamcrest.collection#everyByMatcher() 15 | * 16 | * @example 17 | * 18 | * var items:Array = [{ value: 100 }, { value: 50 }, { value: 20 }]; 19 | * var anyItemValid:Boolean = someByMatcher(items, hasProperties({ value: lessThan(50) })); 20 | * if (anyItemValid) { 21 | * // ... 22 | * } 23 | * 24 | */ 25 | public function someByMatcher(arrayLike:Object, elementMatcher:Matcher):Boolean 26 | { 27 | for each (var item:* in arrayLike) 28 | { 29 | if (elementMatcher.matches(item)) 30 | { 31 | return true; 32 | } 33 | } 34 | 35 | return false; 36 | } 37 | } -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/filter/IFilterFunction.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.filter 2 | { 3 | import flash.events.IEventDispatcher; 4 | 5 | import org.hamcrest.Matcher; 6 | 7 | /** 8 | * Dispatched when the matcher specified for an IFilterFunction is changed. 9 | */ 10 | [Event( name="matcherChanged", type="flash.events.Event" )] 11 | 12 | [DefaultProperty("matcher")] 13 | 14 | /** 15 | * Describes the methods an IFilterFunction is expected to implement. 16 | * 17 | * @author John Yanarella 18 | */ 19 | public interface IFilterFunction extends IEventDispatcher 20 | { 21 | [Bindable( "matcherChanged" )] 22 | /** 23 | * MXMLMatcher that defines the filtering criteria for this IFilterFunction. 24 | */ 25 | function get matcher():Matcher; 26 | function set matcher( value:Matcher ):void; 27 | 28 | /** 29 | * Filter Function. 30 | * 31 | * @returns A function that takes an item as a parameter and returns a Boolean value indicating whether the item meets the filtering criteria. 32 | */ 33 | function get filterFunction():Function; 34 | 35 | /** 36 | * Evaluates the specified item to determine if it meets the filtering criteria defined in the matcher. 37 | * 38 | * @param item An Object to evaluate against the filtering criteria. 39 | * @returns A Boolean value indicating whether the item meets the filtering criteria. 40 | */ 41 | function filter( item:Object ):Boolean; 42 | } 43 | } -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/MXMLMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml 2 | { 3 | import flash.events.IEventDispatcher; 4 | 5 | import org.hamcrest.Matcher; 6 | 7 | /** 8 | * Dispatched when the target property changes. 9 | */ 10 | [Event(name='targetChanged', type = 'flash.events.Event')] 11 | 12 | /** 13 | * Dispatched when the description property changes. 14 | */ 15 | [Event(name='descriptionChanged', type = 'flash.events.Event')] 16 | 17 | /** 18 | * Dispatched when the mismatchDescription property changes. 19 | */ 20 | [Event(name='mismatchDescriptionChanged', type = 'flash.events.Event')] 21 | 22 | /** 23 | * Dispatched when the matched property changes. 24 | */ 25 | [Event(name='matchedChanged', type = 'flash.events.Event')] 26 | 27 | /** 28 | * Interface for MXML façades to Hamcrest Matchers. 29 | * 30 | * @author Drew Bourne 31 | */ 32 | public interface MXMLMatcher extends Matcher, IEventDispatcher 33 | { 34 | /** 35 | * Value to match against the Matcher. 36 | */ 37 | function get target():*; 38 | 39 | function set target(value:*):void; 40 | 41 | /** 42 | * Description of the Matcher. 43 | */ 44 | function get description():String; 45 | 46 | /** 47 | * Description of the mismatch if the target does not match the Matcher, or null. 48 | */ 49 | function get mismatchDescription():String; 50 | 51 | /** 52 | * Indicates if the #target matches the Matcher. 53 | */ 54 | function get matched():Boolean; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/MXMLMatcherComposite.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml 2 | { 3 | 4 | /** 5 | * MXMLMatcher interface for Matchers that compose another MXMLMatcher. 6 | * 7 | * @author Drew Bourne 8 | */ 9 | public interface MXMLMatcherComposite extends MXMLMatcher 10 | { 11 | /** 12 | * MXMLMatcher to compose. 13 | */ 14 | function get matcher():MXMLMatcher; 15 | 16 | function set matcher(value:MXMLMatcher):void; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/MXMLMatcherContainer.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * MXMLMatcher interface for Matchers that compose zero or more MXMLMatchers. 7 | * 8 | * @author Drew Bourne 9 | */ 10 | public interface MXMLMatcherContainer extends MXMLMatcher 11 | { 12 | /** 13 | * Array of MXMLMatchers to compose. 14 | */ 15 | [ArrayElementType("org.hamcrest.mxml.MXMLMatcher")] 16 | function get matchers():Array; 17 | 18 | function set matchers(value:Array):void; 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/collection/Array.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.collection 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.collection.array; 5 | import org.hamcrest.mxml.BaseMXMLMatcherContainer; 6 | 7 | /** 8 | * MXML facade for the array() / IsArrayMatcher. 9 | * 10 | * @see org.hamcrest.collection#array() 11 | * @see org.hamcrest.collection.IsArrayMatcher 12 | * 13 | * @example 14 | * 15 | * <hc:Array> 16 | * <hc:EqualTo value="{ 1 }" /> 17 | * <hc:EqualTo value="{ 2 }" /> 18 | * <hc:EqualTo value="{ 3 }" /> 19 | * <hc:Array> 20 | * 21 | * 22 | * @author Drew Bourne 23 | */ 24 | public class Array extends BaseMXMLMatcherContainer 25 | { 26 | /** 27 | * Constructor. 28 | */ 29 | public function Array() 30 | { 31 | super(); 32 | invalidateProperties(); 33 | } 34 | 35 | /** 36 | * @inheritDoc 37 | */ 38 | override protected function createMatcher():Matcher 39 | { 40 | return array.apply(null, matchers || []); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/collection/EmptyArray.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.collection 2 | { 3 | 4 | import org.hamcrest.Matcher; 5 | import org.hamcrest.collection.emptyArray; 6 | import org.hamcrest.mxml.BaseMXMLMatcher; 7 | 8 | /** 9 | * MXML facade for the emptyArray() / IsArrayWithSizeMatcher. 10 | * 11 | * @see org.hamcrest.collection#emptyArray() 12 | * @see org.hamcrest.collection.IsArrayWithSizeMatcher 13 | * 14 | * @example 15 | * 16 | * <hc:EmptyArray /> 17 | * 18 | * 19 | * @author Drew Bourne 20 | */ 21 | public class EmptyArray extends BaseMXMLMatcher 22 | { 23 | private var _size:int; 24 | 25 | /** 26 | * Constructor. 27 | */ 28 | public function EmptyArray() 29 | { 30 | super(); 31 | invalidateProperties(); 32 | } 33 | 34 | /** 35 | * @inheritDoc 36 | */ 37 | override protected function createMatcher():Matcher 38 | { 39 | return emptyArray(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/collection/EveryItem.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.collection 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.collection.everyItem; 5 | import org.hamcrest.mxml.BaseMXMLMatcherComposite; 6 | 7 | /** 8 | * MXML facade for the everyItem() / EveryMatcher. 9 | * 10 | * @see org.hamcrest.collection#everyItem() 11 | * @see org.hamcrest.collection.EveryMatcher 12 | * 13 | * @example 14 | * 15 | * <hc:EveryItem> 16 | * <hc:EqualTo value="{ 3 }" /> 17 | * <hc:EveryItem> 18 | * 19 | * 20 | * @author Drew Bourne 21 | */ 22 | public class EveryItem extends BaseMXMLMatcherComposite 23 | { 24 | /** 25 | * Constructor. 26 | */ 27 | public function EveryItem() 28 | { 29 | super(); 30 | } 31 | 32 | /** 33 | * @inheritDoc 34 | */ 35 | override protected function createMatcher():Matcher 36 | { 37 | return everyItem(matcher); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/collection/HasItem.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.collection 2 | { 3 | 4 | import org.hamcrest.Matcher; 5 | import org.hamcrest.collection.hasItem; 6 | import org.hamcrest.mxml.BaseMXMLMatcherComposite; 7 | 8 | /** 9 | * MXML facade for the hasItem() / IsArrayContainingMatcher. 10 | * 11 | * @see org.hamcrest.collection#hasItem() 12 | * @see org.hamcrest.collection.IsArrayContainingMatcher 13 | * 14 | * @example 15 | * 16 | * <hc:EveryItem> 17 | * <hc:EqualTo value="{ 3 }" /> 18 | * <hc:EveryItem> 19 | * 20 | * 21 | * @author Drew Bourne 22 | */ 23 | public class HasItem extends BaseMXMLMatcherComposite 24 | { 25 | /** 26 | * Constructor. 27 | */ 28 | public function HasItem() 29 | { 30 | super(); 31 | } 32 | 33 | /** 34 | * @inheritDoc 35 | */ 36 | override protected function createMatcher():Matcher 37 | { 38 | return hasItem(matcher); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/collection/HasItems.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.collection 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.collection.hasItems; 5 | import org.hamcrest.mxml.BaseMXMLMatcherContainer; 6 | 7 | /** 8 | * MXML facade for the hasItems() / IsArrayContainingMatcher. 9 | * 10 | * @see org.hamcrest.collection#hasItems() 11 | * @see org.hamcrest.collection.IsArrayContainingMatcher 12 | * 13 | * @example 14 | * 15 | * <hc:HasItems> 16 | * <hc:EqualTo value="{ 3 }" /> 17 | * <hc:EqualTo value="{ 4 }" /> 18 | * <hc:EqualTo value="{ 5 }" /> 19 | * <hc:HasItems> 20 | * 21 | * 22 | * @author Drew Bourne 23 | */ 24 | public class HasItems extends BaseMXMLMatcherContainer 25 | { 26 | /** 27 | * Constructor. 28 | */ 29 | public function HasItems() 30 | { 31 | super(); 32 | } 33 | 34 | /** 35 | * @inheritDoc 36 | */ 37 | override protected function createMatcher():Matcher 38 | { 39 | return hasItems.apply(null, matchers); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/collection/InArray.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.collection 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.collection.inArray; 5 | import org.hamcrest.mxml.BaseMXMLMatcher; 6 | 7 | [DefaultProperty("elements")] 8 | 9 | /** 10 | * 11 | */ 12 | public class InArray extends BaseMXMLMatcher 13 | { 14 | private var _elements:Array; 15 | 16 | /** 17 | * Constructor. 18 | */ 19 | public function InArray() 20 | { 21 | super(); 22 | invalidateProperties(); 23 | } 24 | 25 | /** 26 | * Array of elements (values or Matchers). 27 | */ 28 | [ArrayElementType('Object')] 29 | [Bindable('elementsChanged')] 30 | public function get elements():Array 31 | { 32 | return _elements; 33 | } 34 | 35 | public function set elements(value:Array):void 36 | { 37 | if (_elements != value) 38 | { 39 | _elements = value; 40 | changed('elements'); 41 | } 42 | } 43 | 44 | /** 45 | * @inheritDoc 46 | */ 47 | override protected function createMatcher():Matcher 48 | { 49 | return inArray.apply(null, elements || []); 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/core/AllOf.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.core 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.core.allOf; 5 | import org.hamcrest.mxml.BaseMXMLMatcherContainer; 6 | 7 | /** 8 | * MXML facade for the allOf() / AllOfMatcher. 9 | * 10 | * @see org.hamcrest.core#allOf() 11 | * @see org.hamcrest.core.AllOfMatcher 12 | * 13 | * @example 14 | * 15 | * <hc:AllOf> 16 | * <hc:NotNull /> 17 | * <hc:Between min="{ 1 }" max="{ 5 }" /> 18 | * <hc:CloseTo value="{ 4 }" delta="{ 0.3 }" /> 19 | * <hc:AllOf> 20 | * 21 | * 22 | * @author Drew Bourne 23 | */ 24 | public class AllOf extends BaseMXMLMatcherContainer 25 | { 26 | /** 27 | * Constructor. 28 | */ 29 | public function AllOf() 30 | { 31 | super(); 32 | } 33 | 34 | /** 35 | * @inheritDoc 36 | */ 37 | override protected function createMatcher():Matcher 38 | { 39 | return allOf.apply(null, matchers); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/core/AnyOf.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.core 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.core.anyOf; 5 | import org.hamcrest.mxml.BaseMXMLMatcherContainer; 6 | 7 | /** 8 | * MXML facade for the anyOf() / AnyOfMatcher. 9 | * 10 | * @see org.hamcrest.core#anyOf() 11 | * @see org.hamcrest.core.AnyOfMatcher 12 | * 13 | * @example 14 | * 15 | * <hc:AnyOf> 16 | * <hc:EqualTo value="{ 3 }" /> 17 | * <hc:EqualTo value="{ 4 }" /> 18 | * <hc:EqualTo value="{ 5 }" /> 19 | * <hc:AnyOf> 20 | * 21 | * 22 | * @author Drew Bourne 23 | */ 24 | public class AnyOf extends BaseMXMLMatcherContainer 25 | { 26 | /** 27 | * Constructor. 28 | */ 29 | public function AnyOf() 30 | { 31 | super(); 32 | } 33 | 34 | /** 35 | * @inheritDoc 36 | */ 37 | override protected function createMatcher():Matcher 38 | { 39 | return anyOf.apply(null, matchers); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/core/Anything.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.core 2 | { 3 | 4 | import org.hamcrest.Matcher; 5 | import org.hamcrest.core.anything; 6 | import org.hamcrest.mxml.BaseMXMLMatcher; 7 | 8 | /** 9 | * MXML facade for the anything() / IsAnythingMatcher. 10 | * 11 | * @see org.hamcrest.core#anything() 12 | * @see org.hamcrest.core.IsAnythingMatcher 13 | * 14 | * @example 15 | * 16 | * <hc:Anything /> 17 | * 18 | * 19 | * @author Drew Bourne 20 | */ 21 | public class Anything extends BaseMXMLMatcher 22 | { 23 | /** 24 | * Constructor. 25 | */ 26 | public function Anything() 27 | { 28 | super(); 29 | invalidateProperties(); 30 | } 31 | 32 | /** 33 | * @inheritDoc 34 | */ 35 | override protected function createMatcher():Matcher 36 | { 37 | return anything(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/core/Not.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.core 2 | { 3 | import org.hamcrest.Description; 4 | import org.hamcrest.Matcher; 5 | import org.hamcrest.core.not; 6 | import org.hamcrest.mxml.BaseMXMLMatcherComposite; 7 | 8 | /** 9 | * MXML facade for the not() / IsNotMatcher. 10 | * 11 | * @see org.hamcrest.core#not() 12 | * @see org.hamcrest.core.IsNotMatcher 13 | * 14 | * @example 15 | * 16 | * <hc:Not> 17 | * <hc:EqualTo value="{ 4 }" /> 18 | * <hc:Not> 19 | * 20 | * 21 | * @author Drew Bourne 22 | */ 23 | public class Not extends BaseMXMLMatcherComposite 24 | { 25 | /** 26 | * Constructor. 27 | */ 28 | public function Not() 29 | { 30 | super(); 31 | } 32 | 33 | /** 34 | * @inheritDoc 35 | */ 36 | override protected function createMatcher():Matcher 37 | { 38 | return not(matcher); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/date/DateAfter.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.date 2 | { 3 | import flash.events.Event; 4 | 5 | import org.hamcrest.Matcher; 6 | import org.hamcrest.date.dateAfter; 7 | import org.hamcrest.mxml.BaseMXMLMatcher; 8 | 9 | /** 10 | * MXML facade for the dateAfter() / DateAfterMatcher. 11 | * 12 | * @see org.hamcrest.date#dateAfter() 13 | * @see org.hamcrest.date.DateAfterMatcher 14 | * 15 | * @example 16 | * 17 | * <hc:DateAfter date="{ new Date() }" /> 18 | * 19 | * 20 | * @author Drew Bourne 21 | */ 22 | public class DateAfter extends BaseMXMLMatcher 23 | { 24 | private var _date:Date; 25 | 26 | /** 27 | * Constructor. 28 | */ 29 | public function DateAfter() 30 | { 31 | super(); 32 | } 33 | 34 | /** 35 | * Date the target value must be after. 36 | */ 37 | [Bindable('dateChanged')] 38 | public function get date():Date 39 | { 40 | return _date; 41 | } 42 | 43 | public function set date(value:Date):void 44 | { 45 | if (_date != value) 46 | { 47 | _date = value; 48 | changed('date'); 49 | } 50 | } 51 | 52 | /** 53 | * @inheritDoc 54 | */ 55 | override protected function createMatcher():Matcher 56 | { 57 | return dateAfter(date); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/date/DateBefore.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.date 2 | { 3 | import flash.events.Event; 4 | 5 | import org.hamcrest.Matcher; 6 | import org.hamcrest.date.dateBefore; 7 | import org.hamcrest.mxml.BaseMXMLMatcher; 8 | 9 | /** 10 | * MXML facade for the dateBefore() / DateBeforeMatcher. 11 | * 12 | * @see org.hamcrest.date#dateBefore() 13 | * @see org.hamcrest.date.DateBeforeMatcher 14 | * 15 | * @example 16 | * 17 | * <hc:DateBefore date="{ new Date() }" /> 18 | * 19 | */ 20 | public class DateBefore extends BaseMXMLMatcher 21 | { 22 | private var _date:Date; 23 | 24 | /** 25 | * Constructor. 26 | */ 27 | public function DateBefore() 28 | { 29 | super(); 30 | } 31 | 32 | /** 33 | * Date the target value must be before. 34 | */ 35 | [Bindable('dateChanged')] 36 | public function get date():Date 37 | { 38 | return _date; 39 | } 40 | 41 | public function set date(value:Date):void 42 | { 43 | if (_date != value) 44 | { 45 | _date = value; 46 | changed('date'); 47 | } 48 | } 49 | 50 | /** 51 | * @inheritDoc 52 | */ 53 | override protected function createMatcher():Matcher 54 | { 55 | return dateBefore(date); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/date/DateEqualTo.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.date 2 | { 3 | import flash.events.Event; 4 | 5 | import org.hamcrest.Matcher; 6 | import org.hamcrest.date.dateEqual; 7 | import org.hamcrest.mxml.BaseMXMLMatcher; 8 | 9 | /** 10 | * MXML facade for the dateEqual() / DateEqualMatcher 11 | * 12 | * @see org.hamcrest.date#dateEqual() 13 | * @see org.hamcrest.date.DateEqualMatcher 14 | * 15 | * @example 16 | * 17 | * <hc:DateEqualTo date="{ new Date() }" /> 18 | * 19 | * 20 | * @author Drew Bourne 21 | */ 22 | public class DateEqualTo extends BaseMXMLMatcher 23 | { 24 | private var _date:Date; 25 | 26 | /** 27 | * Constructor. 28 | */ 29 | public function DateEqualTo() 30 | { 31 | super(); 32 | } 33 | 34 | /** 35 | * Date the target value must be equal to. 36 | */ 37 | [Bindable('dateChanged')] 38 | public function get date():Date 39 | { 40 | return _date; 41 | } 42 | 43 | public function set date(value:Date):void 44 | { 45 | if (_date != value) 46 | { 47 | _date = value; 48 | changed('date'); 49 | } 50 | } 51 | 52 | /** 53 | * @inheritDoc 54 | */ 55 | override protected function createMatcher():Matcher 56 | { 57 | return dateEqual(date); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/number/GreaterThan.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.number 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.mxml.BaseMXMLMatcher; 5 | import org.hamcrest.number.greaterThan; 6 | 7 | /** 8 | * MXML facade for the greaterThan() / IsGreaterThanMatcher. 9 | * 10 | * @see org.hamcrest.number#greaterThan() 11 | * @see org.hamcrest.number.IsGreaterThanMatcher 12 | * 13 | * @example 14 | * 15 | * <hc:GreaterThan value="{ 4 }" /> 16 | * 17 | * 18 | * @author Drew Bourne 19 | */ 20 | public class GreaterThan extends BaseMXMLMatcher 21 | { 22 | 23 | private var _value:Number; 24 | 25 | /** 26 | * Constructor. 27 | */ 28 | public function GreaterThan() 29 | { 30 | super(); 31 | } 32 | 33 | /** 34 | * Number the target value must be greater than. 35 | */ 36 | [Bindable('valueChanged')] 37 | public function get value():Number 38 | { 39 | return _value; 40 | } 41 | 42 | public function set value(value:Number):void 43 | { 44 | if (_value != value) 45 | { 46 | _value = value; 47 | changed('value'); 48 | } 49 | } 50 | 51 | /** 52 | * @inheritDoc 53 | */ 54 | override protected function createMatcher():Matcher 55 | { 56 | return greaterThan(value); 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/number/GreaterThanOrEqualTo.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.number 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.mxml.BaseMXMLMatcher; 5 | import org.hamcrest.number.greaterThanOrEqualTo; 6 | 7 | /** 8 | * MXML facade for the greaterThanOrEqualTo() / IsGreaterThanMatcher. 9 | * 10 | * @see org.hamcrest.number#greaterThanOrEqualTo() 11 | * @see org.hamcrest.number.IsGreaterThanMatcher 12 | * 13 | * @example 14 | * 15 | * <hc:GreaterThanOrEqualTo value="{ 4 }" /> 16 | * 17 | * 18 | * @author Drew Bourne 19 | */ 20 | public class GreaterThanOrEqualTo extends BaseMXMLMatcher 21 | { 22 | private var _value:Number; 23 | 24 | /** 25 | * Constructor. 26 | */ 27 | public function GreaterThanOrEqualTo() 28 | { 29 | super(); 30 | } 31 | 32 | /** 33 | * Number the target value must be greater than or equal to. 34 | */ 35 | [Bindable('valueChanged')] 36 | public function get value():Number 37 | { 38 | return _value; 39 | } 40 | 41 | public function set value(value:Number):void 42 | { 43 | if (_value != value) 44 | { 45 | _value = value; 46 | changed('value'); 47 | } 48 | } 49 | 50 | /** 51 | * @inheritDoc 52 | */ 53 | override protected function createMatcher():Matcher 54 | { 55 | return greaterThanOrEqualTo(value); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/number/LessThan.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.number 2 | { 3 | 4 | import org.hamcrest.Matcher; 5 | import org.hamcrest.mxml.BaseMXMLMatcher; 6 | import org.hamcrest.number.lessThan; 7 | 8 | /** 9 | * MXML facade for the lessThan() / IsLessThanMatcher. 10 | * 11 | * @see org.hamcrest.number#lessThan() 12 | * @see org.hamcrest.number.IsLessThanMatcher 13 | * 14 | * @example 15 | * 16 | * <hc:LessThan value="{ 4 }" /> 17 | * 18 | * 19 | * @author Drew Bourne 20 | */ 21 | public class LessThan extends BaseMXMLMatcher 22 | { 23 | private var _value:Number; 24 | 25 | /** 26 | * Constructor. 27 | */ 28 | public function LessThan() 29 | { 30 | super(); 31 | } 32 | 33 | /** 34 | * Number the target value must be less than. 35 | */ 36 | [Bindable('valueChanged')] 37 | public function get value():Number 38 | { 39 | return _value; 40 | } 41 | 42 | public function set value(value:Number):void 43 | { 44 | if (_value != value) 45 | { 46 | _value = value; 47 | changed('value'); 48 | } 49 | } 50 | 51 | /** 52 | * @inheritDoc 53 | */ 54 | override protected function createMatcher():Matcher 55 | { 56 | return lessThan(value); 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/number/LessThanOrEqualTo.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.number 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.mxml.BaseMXMLMatcher; 5 | import org.hamcrest.number.lessThanOrEqualTo; 6 | 7 | /** 8 | * MXML facade for the lessThanOrEqualTo() / IsLessThanMatcher. 9 | * 10 | * @see org.hamcrest.number#lessThanOrEqualTo() 11 | * @see org.hamcrest.number.IsLessThanMatcher 12 | * 13 | * @example 14 | * 15 | * <hc:LessThanOrEqualTo value="{ 4 }" /> 16 | * 17 | * 18 | * @author Drew Bourne 19 | */ 20 | public class LessThanOrEqualTo extends BaseMXMLMatcher 21 | { 22 | private var _value:Number; 23 | 24 | /** 25 | * Constructor. 26 | */ 27 | public function LessThanOrEqualTo() 28 | { 29 | super(); 30 | } 31 | 32 | /** 33 | * Number the target value must be less than. 34 | */ 35 | [Bindable('valueChanged')] 36 | public function get value():Number 37 | { 38 | return _value; 39 | } 40 | 41 | public function set value(value:Number):void 42 | { 43 | if (_value != value) 44 | { 45 | _value = value; 46 | changed('value'); 47 | } 48 | } 49 | 50 | /** 51 | * @inheritDoc 52 | */ 53 | override protected function createMatcher():Matcher 54 | { 55 | return lessThanOrEqualTo(value); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/object/IsFalse.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.object 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.mxml.BaseMXMLMatcher; 5 | import org.hamcrest.object.isFalse; 6 | 7 | /** 8 | * Matches target if it is false 9 | * 10 | * @see org.hamcrest.object#isFalse() 11 | * 12 | * @example 13 | * 14 | * <hc:IsFalse target="{ checkBox.selected }" /> 15 | * 16 | * 17 | * @author Drew Bourne 18 | */ 19 | public class IsFalse extends BaseMXMLMatcher 20 | { 21 | /** 22 | * Constructor. 23 | */ 24 | public function IsFalse() 25 | { 26 | super(); 27 | 28 | invalidateProperties(); 29 | } 30 | 31 | /** 32 | * Create an a Matcher using isFalse() 33 | */ 34 | override protected function createMatcher():Matcher 35 | { 36 | return isFalse(); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/object/IsTrue.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.object 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.mxml.BaseMXMLMatcher; 5 | import org.hamcrest.object.isTrue; 6 | 7 | /** 8 | * Matches target if it is true 9 | * 10 | * @see org.hamcrest.object#isTrue() 11 | * 12 | * @example 13 | * 14 | * <hc:IsTrue target="{ checkBox.selected }" /> 15 | * 16 | * 17 | * @author Drew Bourne 18 | */ 19 | public class IsTrue extends BaseMXMLMatcher 20 | { 21 | /** 22 | * Constructor. 23 | */ 24 | public function IsTrue() 25 | { 26 | super(); 27 | 28 | invalidateProperties(); 29 | } 30 | 31 | /** 32 | * Create an a Matcher using isTrue() 33 | */ 34 | override protected function createMatcher():Matcher 35 | { 36 | return isTrue(); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/object/NotNull.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.object 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.mxml.BaseMXMLMatcher; 5 | import org.hamcrest.object.notNullValue; 6 | 7 | /** 8 | * MXML façade for notNullValue() 9 | * 10 | * @see org.hamcrest.core#not() 11 | * @see org.hamcrest.object#nullValue() 12 | * @see org.hamcrest.object#notNullValue() 13 | * @see org.hamcrest.object.IsNullMatcher 14 | * 15 | * @example 16 | * 17 | * <hc:NotNull /> 18 | * 19 | * 20 | * @author Drew Bourne 21 | */ 22 | public class NotNull extends BaseMXMLMatcher 23 | { 24 | /** 25 | * Constructor. 26 | */ 27 | public function NotNull() 28 | { 29 | super(); 30 | invalidateProperties(); 31 | } 32 | 33 | /** 34 | * @inheritDoc 35 | */ 36 | override protected function createMatcher():Matcher 37 | { 38 | return notNullValue(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/object/Null.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.object 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.mxml.BaseMXMLMatcher; 5 | import org.hamcrest.object.nullValue; 6 | 7 | /** 8 | * MXML façade for nullValue / IsNullMatcher. 9 | * 10 | * @see org.hamcrest.object#nullValue() 11 | * @see org.hamcrest.object.IsNullMatcher 12 | * 13 | * @example 14 | * 15 | * <hc:Null /> 16 | * 17 | * 18 | * @author Drew Bourne 19 | */ 20 | public class Null extends BaseMXMLMatcher 21 | { 22 | /** 23 | * Constructor. 24 | */ 25 | public function Null() 26 | { 27 | super(); 28 | invalidateProperties(); 29 | } 30 | 31 | /** 32 | * @inheritDoc 33 | */ 34 | override protected function createMatcher():Matcher 35 | { 36 | return nullValue(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/text/ContainsString.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.text 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.mxml.BaseMXMLMatcher; 5 | import org.hamcrest.text.containsString; 6 | 7 | /** 8 | * MXML façade for containsString() / StringContainsMatcher. 9 | * 10 | * @see org.hamcrest.text#containsString() 11 | * @see org.hamcrest.text.StringContainsMatcher 12 | * 13 | * @example 14 | * 15 | * <hc:ContainsString string="string that should be contained" /> 16 | * 17 | * <hc:ContainsString> 18 | * <![CDATA[ 19 | * multiline strings 20 | * can be matched too 21 | * ]]> 22 | * <hc:ContainsString> 23 | * 24 | * 25 | * @author Drew Bourne 26 | */ 27 | public class ContainsString extends StringMXMLMatcher 28 | { 29 | /** 30 | * Constructor. 31 | */ 32 | public function ContainsString() 33 | { 34 | super(); 35 | } 36 | 37 | /** 38 | * @inheritDoc 39 | */ 40 | override protected function createMatcher():Matcher 41 | { 42 | return containsString(string, ignoreCase); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/text/EmptyString.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.text 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.mxml.BaseMXMLMatcher; 5 | import org.hamcrest.text.emptyString; 6 | 7 | /** 8 | * MXML wrapper for EmptyStringMatcher. 9 | * 10 | * @see org.hamcrest.text#emptyString() 11 | * @see org.hamcrest.text.EmptyStringMatcher 12 | * 13 | * @author Drew Bourne 14 | */ 15 | public class EmptyString extends BaseMXMLMatcher 16 | { 17 | /** 18 | * Constructor. 19 | */ 20 | public function EmptyString() 21 | { 22 | super(); 23 | 24 | // as we have no property changes we force a call to commitProperties 25 | // in order to initialize the description 26 | commitProperties(); 27 | } 28 | 29 | /** 30 | * @inheritDoc 31 | */ 32 | override protected function createMatcher():Matcher 33 | { 34 | return emptyString(); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/text/EndsWith.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.text 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.mxml.BaseMXMLMatcher; 5 | import org.hamcrest.text.endsWith; 6 | 7 | /** 8 | * MXML façade for endsWith() / StringEndsWithMatcher 9 | * 10 | * @see org.hamcrest.text#endsWith() 11 | * @see org.hamcrest.text.StringEndsWithMatcher 12 | * 13 | * @example 14 | * 15 | * <hc:EndsWith string="lazy dog" /> 16 | * 17 | * 18 | * @author Drew Bourne 19 | */ 20 | public class EndsWith extends StringMXMLMatcher 21 | { 22 | /** 23 | * Constructor. 24 | */ 25 | public function EndsWith() 26 | { 27 | super(); 28 | } 29 | 30 | /** 31 | * @inheritDoc 32 | */ 33 | override protected function createMatcher():Matcher 34 | { 35 | return endsWith(string, ignoreCase); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /hamcrest/src-flex/org/hamcrest/mxml/text/StartsWith.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.mxml.text 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.mxml.BaseMXMLMatcher; 5 | import org.hamcrest.text.startsWith; 6 | 7 | /** 8 | * MXML façade for startsWith() / StringStartsWithMatcher 9 | * 10 | * @see org.hamcrest.text#startsWith() 11 | * @see org.hamcrest.text.StringStartsWithMatcher 12 | * 13 | * @example 14 | * 15 | * <hc:StringWith string="the quick brown fox" /> 16 | * 17 | * 18 | * @author Drew Bourne 19 | */ 20 | public class StartsWith extends StringMXMLMatcher 21 | { 22 | /** 23 | * Constructor. 24 | */ 25 | public function StartsWith() 26 | { 27 | super(); 28 | } 29 | 30 | /** 31 | * @inheritDoc 32 | */ 33 | override protected function createMatcher():Matcher 34 | { 35 | return startsWith(string, ignoreCase); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /hamcrest/src/hamcrest-config.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/hamcrest/src/hamcrest-config.xml -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/DiagnosingMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest 2 | { 3 | import flash.errors.IllegalOperationError; 4 | 5 | /** 6 | * Combines matching (matches) and describing mismatches (describeMismatch) into a single method matchesOrDescribesMismatch. 7 | * 8 | * Typically used when the matching logic and description logic are the same and/or deferred to another Matcher. 9 | * 10 | * @author Drew Bourne 11 | */ 12 | public class DiagnosingMatcher extends BaseMatcher 13 | { 14 | /** 15 | * Deferred to matchesOrDescribesMismatch. 16 | * 17 | * @see #matchesOrDescribesMismatch 18 | */ 19 | override public function matches(item:Object):Boolean 20 | { 21 | return matchesOrDescribesMismatch(item, new NullDescription()); 22 | } 23 | 24 | /** 25 | * Deferred to matchesOrDescribesMismatch. 26 | * 27 | * @see #matchesOrDescribesMismatch 28 | */ 29 | override public function describeMismatch(item:Object, description:Description):void 30 | { 31 | matchesOrDescribesMismatch(item, description); 32 | } 33 | 34 | /** 35 | * Abstract. Subclasses should override to provide the combined logic for matching and describing mismatches. 36 | */ 37 | protected function matchesOrDescribesMismatch(item:Object, description:Description):Boolean 38 | { 39 | throw new IllegalOperationError('DiagnosingMatcher#matches is abstract and must be overriden in a subclass'); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/Matcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest 2 | { 3 | /** 4 | * Describes methods a Matcher is expected to implement. 5 | * 6 | * @author Drew Bourne 7 | */ 8 | public interface Matcher extends SelfDescribing 9 | { 10 | /** 11 | * Given an item, a Matcher implementation should return true if the item is correct, false if the item is not wrong. 12 | */ 13 | function matches(item:Object):Boolean; 14 | 15 | /** 16 | * When a Matcher returns false describeMismatch can be called with a Description, to which this matcher will describe how the item was wrong. 17 | * 18 | * @see org.hamcrest.Description 19 | */ 20 | function describeMismatch(item:Object, mismatchDescription:Description):void; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/NullDescription.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest 2 | { 3 | import org.hamcrest.Description; 4 | import org.hamcrest.SelfDescribing; 5 | 6 | /** 7 | * No-Op implementation of Description. 8 | * 9 | * @author Drew Bourne 10 | */ 11 | public class NullDescription implements Description 12 | { 13 | /** 14 | * Returns an empty String 15 | */ 16 | public function toString():String 17 | { 18 | return ""; 19 | } 20 | 21 | /** 22 | * No-op. 23 | * @return this 24 | */ 25 | public function appendText(text:String):Description 26 | { 27 | return this; 28 | } 29 | 30 | /** 31 | * No-op. 32 | * @return this 33 | */ 34 | public function appendDescriptionOf(value:SelfDescribing):Description 35 | { 36 | return this; 37 | } 38 | 39 | /** 40 | * No-op. 41 | * @return this 42 | */ 43 | public function appendMismatchOf(matcher:Matcher, value:*):Description 44 | { 45 | return this; 46 | } 47 | 48 | /** 49 | * No-op. 50 | * @return this 51 | */ 52 | public function appendValue(value:Object):Description 53 | { 54 | return this; 55 | } 56 | 57 | /** 58 | * No-op. 59 | * @return this 60 | */ 61 | public function appendList(start:String, separator:String, end:String, list:Array):Description 62 | { 63 | return this; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/SelfDescribing.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest 2 | { 3 | 4 | // TODO example SelfDescribing 5 | /** 6 | * An implementation of SelfDescribing should describe itself in as much detail as relevant. 7 | * 8 | * @author Drew Bourne 9 | */ 10 | public interface SelfDescribing 11 | { 12 | /** 13 | * Given a Description, an implementation should describe itself is as much detail as relevant. 14 | */ 15 | function describeTo(description:Description):void; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/StringDescription.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest 2 | { 3 | 4 | /** 5 | * Description implementation that appends to a String. 6 | * 7 | * To get result call toString(). 8 | * 9 | * @see org.hamcrest.Description 10 | * 11 | * @author Drew Bourne 12 | */ 13 | public class StringDescription extends BaseDescription 14 | { 15 | /** 16 | * Converts a SelfDescribing implementation into a String. 17 | * 18 | * @see org.hamcrest.SelfDescribing 19 | */ 20 | public static function toString(selfDescribing:SelfDescribing):String 21 | { 22 | return (new StringDescription()).appendDescriptionOf(selfDescribing).toString(); 23 | } 24 | 25 | private var _out:String; 26 | 27 | /** 28 | * Constructor. 29 | */ 30 | public function StringDescription() 31 | { 32 | clear(); 33 | } 34 | 35 | /** 36 | * Appends the string to the description. 37 | */ 38 | override protected function append(string:Object):void 39 | { 40 | _out += String(string); 41 | } 42 | 43 | /** 44 | * Clears the StringDescription buffer. 45 | */ 46 | public function clear():void 47 | { 48 | _out = ""; 49 | } 50 | 51 | /** 52 | * Returns a String of the description. 53 | */ 54 | override public function toString():String 55 | { 56 | return _out; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/assertThatBoolean.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest 2 | { 3 | 4 | /** 5 | * Used internally by assertThat. 6 | * 7 | * @param reason Description of failure if result is false. 8 | * @param result Boolean indicating a pass if true or a failure if false 9 | * 10 | * @private 11 | * 12 | * @author Drew Bourne 13 | */ 14 | internal function assertThatBoolean(reason:String, result:Boolean):void 15 | { 16 | if (!result) 17 | { 18 | throw new AssertionError(reason, null, null, null, result); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/assertThatMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest 2 | { 3 | /** 4 | * Used internally by assertThat. 5 | * 6 | * @param reason Description of failure should actual not match matcher 7 | * @param actual Object to match 8 | * @param matcher Matcher to match actual with. 9 | * 10 | * @author Drew Bourne 11 | */ 12 | internal function assertThatMatcher(reason:String, actual:Object, matcher:Matcher):void 13 | { 14 | if (!matcher.matches(actual)) 15 | { 16 | var errorDescription:Description = new StringDescription(); 17 | var matcherDescription:Description = new StringDescription(); 18 | var mismatchDescription:Description = new StringDescription(); 19 | 20 | if (reason && reason.length > 0) 21 | { 22 | errorDescription 23 | .appendText(reason) 24 | .appendText("\n"); 25 | } 26 | 27 | errorDescription 28 | .appendText("Expected: ") 29 | .appendDescriptionOf(matcher) 30 | .appendText("\n but: ") 31 | .appendMismatchOf(matcher, actual); 32 | 33 | matcherDescription.appendDescriptionOf(matcher); 34 | 35 | mismatchDescription.appendMismatchOf(matcher, actual); 36 | 37 | throw new AssertionError( 38 | errorDescription.toString(), 39 | null, 40 | matcherDescription.toString(), 41 | mismatchDescription.toString(), 42 | actual); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/collection/InArrayMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.collection 2 | { 3 | import org.hamcrest.Description; 4 | import org.hamcrest.DiagnosingMatcher; 5 | import org.hamcrest.Matcher; 6 | 7 | public class InArrayMatcher extends DiagnosingMatcher 8 | { 9 | private var _elementMatchers:Array; 10 | 11 | public function InArrayMatcher(elementMatchers:Array) 12 | { 13 | super(); 14 | 15 | _elementMatchers = elementMatchers; 16 | } 17 | 18 | override protected function matchesOrDescribesMismatch(item:Object, description:Description):Boolean 19 | { 20 | for each (var element:Matcher in _elementMatchers) 21 | { 22 | if (element.matches(item)) 23 | { 24 | return true; 25 | } 26 | } 27 | 28 | description.appendValue(item); 29 | description.appendText(" was not "); 30 | describeTo(description); 31 | 32 | return false; 33 | } 34 | 35 | override public function describeTo(description:Description):void 36 | { 37 | description.appendText("contained in "); 38 | description.appendList("[", ", ", "]", _elementMatchers); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/collection/arrayWithSize.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.collection 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.object.equalTo; 5 | 6 | // FIXME arrayWithSize() should take a matcher for the size, to allow usage of lessThan(), greaterThan(), between() etc. 7 | // FIXME test arrayWithSize() behaviour when taking a Matcher 8 | /** 9 | * Checks the item being matched is an Array and has the expected number of items. 10 | * 11 | * @param size Number, int, uint in the range of >= 0. 12 | * 13 | * @see org.hamcrest.collection.IsArrayWithSizeMatcher 14 | * @example 15 | * 16 | * assertThat([], arrayWithSize(0)); 17 | * 18 | * 19 | * @author Drew Bourne 20 | */ 21 | public function arrayWithSize(size:*):Matcher 22 | { 23 | if (size is Number || size is int || size is uint) 24 | { 25 | return arrayWithSize(equalTo(size)); 26 | } 27 | else if (size is Matcher) 28 | { 29 | return new IsArrayWithSizeMatcher(size as Matcher); 30 | } 31 | else 32 | { 33 | throw new ArgumentError("Expecting Number, int, or uint for size, received:" + size); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/collection/emptyArray.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.collection 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.core.describedAs; 5 | 6 | /** 7 | * Checks item being matched is an Array and has zero (0) items. 8 | * 9 | * @example 10 | * 11 | * assertThat([], emptyArray()); 12 | * 13 | * 14 | * @author Drew Bourne 15 | */ 16 | public function emptyArray():Matcher 17 | { 18 | return describedAs("an empty Array", arrayWithSize(0)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/collection/everyItem.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.collection 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches an Array or Array-like Object if every item matches the given Matcher. 7 | * 8 | * @param itemMatcher Matcher that each item in the collection being matched must match. 9 | * 10 | * @see org.hamcrest.collection.EveryMatcher 11 | * @example 12 | * 13 | * assertThat([1, 2, 3], everyItem(isA(Number))); 14 | * 15 | * 16 | * @author Drew Bourne 17 | */ 18 | public function everyItem(itemMatcher:Matcher):Matcher 19 | { 20 | return new EveryMatcher(itemMatcher); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/collection/hasItem.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.collection 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.object.equalTo; 5 | 6 | /** 7 | * Matches if the item being matched is an Array and contains at least one item that matches 8 | * the given Matcher. 9 | * 10 | * @param value Object or Matcher that must be in the Array. 11 | * 12 | * @see org.hamcrest.collection.IsArrayContainingMatcher 13 | * @example 14 | * 15 | * assertThat([1, 2, 3], hasItem(equalTo(3)); 16 | * 17 | * 18 | * @author Drew Bourne 19 | */ 20 | public function hasItem(value:Object):Matcher 21 | { 22 | if (value is Matcher) 23 | { 24 | return new IsArrayContainingMatcher(value as Matcher); 25 | } 26 | else 27 | { 28 | return hasItem(equalTo(value)); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/collection/hasItems.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.collection 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.core.allOf; 5 | 6 | /** 7 | * Matches if the item being matched matches with all of the given matchers. 8 | * 9 | * Typically used to check if an Array has the expected items. 10 | * 11 | * @param ...rest Matcher or Object to be wrapped in equalTo 12 | * 13 | * @see org.hamcrest.collection#hasItem() 14 | * @see org.hamcrest.core#allOf() 15 | * @see org.hamcrest.object#equalTo() 16 | * 17 | * @example 18 | * 19 | * assertThat([1, 2, 3, 4], hasItems(equalTo(2), equalTo(4))); 20 | * 21 | * 22 | * @author Drew Bourne 23 | */ 24 | public function hasItems(... rest):Matcher 25 | { 26 | return allOf.apply(null, rest.map(hasItemsIterator)); 27 | } 28 | } 29 | 30 | import org.hamcrest.Matcher; 31 | import org.hamcrest.collection.hasItem; 32 | 33 | internal function hasItemsIterator(value:Object, i:int, a:Array):Matcher 34 | { 35 | return hasItem(value); 36 | } 37 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/collection/inArray.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.collection 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches if the item being matched is in the given Array. 7 | * 8 | * @see org.hamcrest.collection.InArrayMatcher 9 | * @see org.hamcrest.collection#array 10 | * 11 | * @example 12 | * 13 | * assertThat(3, inArray([1, 2, 3])); 14 | * 15 | * 16 | * @author Drew Bourne 17 | */ 18 | public function inArray(...rest):Matcher 19 | { 20 | var matchers:Array = rest; 21 | 22 | if (rest.length == 1 && rest[0] is Array) 23 | { 24 | matchers = rest[0]; 25 | } 26 | 27 | var elementMatchers:Array = matchers.map(wrapInEqualToIfNotMatcher); 28 | 29 | return new InArrayMatcher(elementMatchers); 30 | } 31 | } 32 | 33 | import org.hamcrest.Matcher; 34 | import org.hamcrest.object.equalTo; 35 | 36 | internal function wrapInEqualToIfNotMatcher(item:Object, i:int, a:Array):Matcher 37 | { 38 | return item is Matcher ? item as Matcher : equalTo(item); 39 | } 40 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/collection/sortedBy.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.collection 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches if the item being matched is an Array sorted by the given field, 7 | * and flags. 8 | * 9 | * @param field 10 | * @param caseInsensitive 11 | * @param descending 12 | * @param numeric 13 | * 14 | * @example 15 | * 16 | * assertThat([{ value: 1 }, { value: 3 }], sortedBy('value', false, false, true)); 17 | * 18 | * 19 | * @author Drew Bourne 20 | */ 21 | public function sortedBy(field:String, caseInsensitive:Boolean = false, descending:Boolean = false, numeric:Object = null):Matcher 22 | { 23 | return new SortedByMatcher(field, caseInsensitive, descending, numeric); 24 | } 25 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/collection/sortedByFields.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.collection 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches if the item being matched is an Array sorted by the given array 7 | * of SortField instanes. 8 | * 9 | * @param sortFields Array of SortField 10 | * @return Matcher 11 | * 12 | * @example 13 | * 14 | * assertThat( 15 | * [ 16 | * { field1: 1, field2: 1 }, 17 | * { field1: 1, field2: 2 }, 18 | * { field1: 2, field2: 2 }, 19 | * ], 20 | * sortedByFields([new SortField('field1'), new SortField('field2')])); 21 | * 22 | * 23 | * @author Drew Bourne 24 | */ 25 | public function sortedByFields(sortFields:Array):Matcher 26 | { 27 | return new SortedByFieldsMatcher(sortFields); 28 | } 29 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/core/AnyOfMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.core 2 | { 3 | import org.hamcrest.BaseMatcher; 4 | import org.hamcrest.Description; 5 | import org.hamcrest.DiagnosingMatcher; 6 | import org.hamcrest.Matcher; 7 | 8 | /** 9 | * Checks if an item matches all of the given Matchers. 10 | * 11 | * @see org.hamcrest.core#anyOf() 12 | * 13 | * @author Drew Bourne 14 | */ 15 | public class AnyOfMatcher extends BaseMatcher 16 | { 17 | private var _matchers:Array; 18 | 19 | /** 20 | * Constructor. 21 | * 22 | * @param matchers Array of Matcher instances 23 | */ 24 | public function AnyOfMatcher(matchers:Array) 25 | { 26 | super(); 27 | 28 | // TODO check matchers are actually Matcher instances 29 | _matchers = matchers || []; 30 | } 31 | 32 | /** 33 | * Matches an item with ANY of the matchers given to the constructor. Shortcuts on first match. 34 | */ 35 | override public function matches(item:Object):Boolean 36 | { 37 | for each (var matcher:Matcher in _matchers) 38 | { 39 | if (matcher.matches(item)) 40 | { 41 | return true; 42 | } 43 | } 44 | 45 | return false; 46 | } 47 | 48 | /** 49 | * @inheritDoc 50 | */ 51 | override public function describeTo(description:Description):void 52 | { 53 | description.appendList("(", " or ", ")", _matchers); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/core/IsAnythingMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.core 2 | { 3 | import org.hamcrest.BaseMatcher; 4 | import org.hamcrest.Description; 5 | 6 | /** 7 | * Checks if item being matched is anything, effectively always matches. 8 | * 9 | * @see org.hamcrest.core#anything() 10 | * 11 | * @example 12 | * 13 | * assertThat("the great void", anything()); 14 | * 15 | * 16 | * @author Drew Bourne 17 | */ 18 | public class IsAnythingMatcher extends BaseMatcher 19 | { 20 | private var _message:String; 21 | 22 | /** 23 | * Constructor. 24 | * 25 | * @param message Custom message to use in describeTo 26 | */ 27 | public function IsAnythingMatcher(message:String = null) 28 | { 29 | super(); 30 | _message = message || "ANYTHING"; 31 | } 32 | 33 | /** 34 | * Matches anything, always returns true. 35 | */ 36 | override public function matches(item:Object):Boolean 37 | { 38 | return true; 39 | } 40 | 41 | /** 42 | * Describes this matcher with the message given to the constructor, or 'ANYTHING'. 43 | */ 44 | override public function describeTo(description:Description):void 45 | { 46 | description.appendText(_message); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/core/IsNotMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.core 2 | { 3 | import org.hamcrest.BaseMatcher; 4 | import org.hamcrest.Description; 5 | import org.hamcrest.Matcher; 6 | 7 | /** 8 | * Inverts the result of another Matcher or value. 9 | * 10 | * @see org.hamcrest.core#not() 11 | * 12 | * @example 13 | * 14 | * assertThat(3, not(4)); 15 | * assertThat(3, not(closeTo(10, 1))); 16 | * 17 | * 18 | * @author Drew Bourne 19 | */ 20 | public class IsNotMatcher extends BaseMatcher 21 | { 22 | private var _matcher:Matcher; 23 | 24 | /** 25 | * Constructor. 26 | * 27 | * @param matcher Matcher to invert the result for. 28 | */ 29 | public function IsNotMatcher(matcher:Matcher) 30 | { 31 | _matcher = matcher; 32 | } 33 | 34 | /** 35 | * @inheritDoc 36 | */ 37 | override public function matches(item:Object):Boolean 38 | { 39 | return !_matcher.matches(item); 40 | } 41 | 42 | /** 43 | * @inheritDoc 44 | */ 45 | override public function describeTo(description:Description):void 46 | { 47 | description.appendText("not ").appendDescriptionOf(_matcher); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/core/IsNothingMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.core 2 | { 3 | import org.hamcrest.BaseMatcher; 4 | import org.hamcrest.Description; 5 | 6 | /** 7 | * Never matches. Opposite of anything(). 8 | * 9 | * @param message Custom message to use in describeTo 10 | * 11 | * @see org.hamcrest.core.IsNothingMatcher 12 | * 13 | * @example 14 | * 15 | * assertThat("the great void", nothing()); 16 | * 17 | * 18 | * @author Drew Bourne 19 | */ 20 | public class IsNothingMatcher extends BaseMatcher 21 | { 22 | private var _message:String; 23 | 24 | /** 25 | * Constructor. 26 | * 27 | * @param message Custom message to use in describeTo 28 | */ 29 | public function IsNothingMatcher(message:String = null) 30 | { 31 | super(); 32 | _message = message || "NOTHING"; 33 | } 34 | 35 | /** 36 | * Matches anything, always returns true. 37 | */ 38 | override public function matches(item:Object):Boolean 39 | { 40 | return false; 41 | } 42 | 43 | /** 44 | * Describes this matcher with the message given to the constructor, or 'NOTHING'. 45 | */ 46 | override public function describeTo(description:Description):void 47 | { 48 | description.appendText(_message); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/core/allOf.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.core 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Checks if an item matches all of the given Matchers. 7 | * 8 | * @param ...rest Matcher instances 9 | * 10 | * @see org.hamcrest.core.AllOfMatcher 11 | * 12 | * @example 13 | * 14 | * assertThat("good", allOf(equalTo("good"), not(equalTo("bad")))); 15 | * 16 | * 17 | * @author Drew Bourne 18 | */ 19 | public function allOf(... rest):Matcher 20 | { 21 | var matchers:Array = rest; 22 | 23 | if (rest.length == 1 && rest[0] is Array) 24 | { 25 | matchers = rest[0]; 26 | } 27 | 28 | return new AllOfMatcher(matchers); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/core/anyOf.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.core 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Checks if the item being matched matches any of the given Matchers. 7 | * 8 | * @see org.hamcrest.core.AnyOfMatcher 9 | * 10 | * @example 11 | * 12 | * assertThat("good", anyOf(equalTo("bad"), equalTo("good"))); 13 | * 14 | * 15 | * @author Drew Bourne 16 | */ 17 | public function anyOf(... rest):Matcher 18 | { 19 | // FIXME enable passing a single array to anyOf([ matcher, ...matchers ]) so the matchers can be built out of line. 20 | var matchers:Array = rest; 21 | 22 | if (rest.length == 1 && rest[0] is Array) 23 | { 24 | matchers = rest[0]; 25 | } 26 | 27 | return new AnyOfMatcher(matchers); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/core/anything.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.core 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Always matches. Opposite of nothing(). 7 | * 8 | * @param message Custom message to use in describeTo 9 | * 10 | * @see org.hamcrest.core.IsAnythingMatcher 11 | * @see org.hamcrest.core#nothing() 12 | * 13 | * @example 14 | * 15 | * // all pass 16 | * assertThat("the great void", anything()); 17 | * assertThat(true, anything()); 18 | * assertThat(false, anything()); 19 | * assertThat({}, anything()); 20 | * assertThat(123, anything()); 21 | * 22 | * 23 | * @author Drew Bourne 24 | */ 25 | public function anything(message:String = null):Matcher 26 | { 27 | return new IsAnythingMatcher(message); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/core/both.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.core 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Creates a CombinableMatcher 7 | * 8 | * @see org.hamcrest.core.CombinableMatcher 9 | * 10 | * @example 11 | * 12 | * assertThat("good", both(equalTo("good")).and(not(equalTo("bad")); 13 | * 14 | * 15 | * @author Drew Bourne 16 | */ 17 | public function both(... rest):CombinableMatcher 18 | { 19 | return new CombinableMatcher(rest.length > 1 ? allOf.apply(null, rest) : rest[0]); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/core/describedAs.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.core 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Wraps another Matcher to return a modified description for describeTo. 7 | * 8 | * Can replace values in the description using %n placeholders, where n 9 | * is a number into the extra values given. 10 | * 11 | * @param description Custom message 12 | * @param matcher Matcher to wrap 13 | * @param ...values replacement values for the message 14 | * 15 | * @see org.hamcrest.core.DescribedAsMatcher 16 | * 17 | * @example 18 | * 19 | * assertThat(3, describedAs("%0 is a magic number", equalTo(4), 4); 20 | * 21 | * 22 | * @author Drew Bourne 23 | */ 24 | public function describedAs(description:String, matcher:Matcher, ... values):Matcher 25 | { 26 | return new DescribedAsMatcher(description, matcher, values); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/core/describedAsWithMismatch.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.core 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Wraps another Matcher to return a modified description for describeTo. 7 | * 8 | * Can replace values in the description using %n placeholders, where n 9 | * is a number into the extra values given. 10 | * 11 | * @param description Custom message 12 | * @param mismatchDescription Custom mismatch message 13 | * @param matcher Matcher to wrap 14 | * @param ...values replacement values for the message 15 | * 16 | * @see org.hamcrest.core.DescribedAsMatcher 17 | * 18 | * @example 19 | * 20 | * assertThat(3, describedAsWithMismatch("%0 is a magic number", "%0 is not magic", equalTo(4), 4); 21 | * 22 | * 23 | * @author Drew Bourne 24 | */ 25 | public function describedAsWithMismatch(description:String, mismatchDescription:String, matcher:Matcher, ... values):Matcher 26 | { 27 | return new DescribedAsMatcher(description, matcher, values, mismatchDescription); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/core/either.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.core 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Creates a CombinableMatcher 7 | * 8 | * @see org.hamcrest.core.CombinableMatcher 9 | * 10 | * @example 11 | * 12 | * assertThat("good", either(equalTo("good")).or(not(equalTo("bad")); 13 | * 14 | * 15 | * @author Drew Bourne 16 | */ 17 | public function either(... rest):CombinableMatcher 18 | { 19 | // alias of both, 20 | return both.apply(null, rest); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/core/evaluate.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.core 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches if a specified Boolean condition evaluates to true. 7 | * 8 | * Used in coordination with anyOf and allOf to express 9 | * conditional logic as a short-circuit functional style conditional expression. 10 | * 11 | * @see org.hamcrest.core#given() 12 | * 13 | * @example 14 | * 15 | * assertThat( "evaluate 1 + 1 = 2", evaluate( 1 + 1 == 2 ) ); 16 | * assertThat( "evaluate nameInput.enabled", evaluate( nameInput.enabled ), nameInput.text ); 17 | * assertThat( "evaluate anotherMatcher match", evaluate( anotherMatcher.matches( value ) ), value ); 18 | * 19 | * 20 | * @author John Yanarella 21 | */ 22 | public function evaluate( condition:Boolean ):Matcher 23 | { 24 | return new EvaluateMatcher( condition ); 25 | } 26 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/core/isA.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.core 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.object.equalTo; 5 | import org.hamcrest.object.instanceOf; 6 | 7 | // TODO example isA 8 | /** 9 | * Decorates another Matcher, retaining the behavior but allowing tests 10 | * to be slightly more expressive. 11 | * 12 | * @see org.hamcrest.core.IsMatcher 13 | * 14 | * @author Drew Bourne 15 | */ 16 | public function isA(value:Object):Matcher 17 | { 18 | if (value is Class) 19 | { 20 | return isA(instanceOf(value as Class)); 21 | } 22 | 23 | if (value is Matcher) 24 | { 25 | return new IsMatcher(value as Matcher); 26 | } 27 | 28 | return isA(equalTo(value)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/core/not.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.core 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.object.equalTo; 5 | 6 | /** 7 | * Inverts the result of another Matcher or value. 8 | * 9 | * @see org.hamcrest.core.IsNotMatcher 10 | * 11 | * @example 12 | * 13 | * assertThat(3, not(4)); 14 | * assertThat(3, not(closeTo(10, 1))); 15 | * 16 | * 17 | * @author Drew Bourne 18 | */ 19 | public function not(value:Object):Matcher 20 | { 21 | if (value is Matcher) 22 | { 23 | return new IsNotMatcher(value as Matcher); 24 | } 25 | else 26 | { 27 | return not(equalTo(value)); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/core/nothing.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.core 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Never matches. Opposite of anything(). 7 | * 8 | * @param message Custom message to use in describeTo 9 | * 10 | * @see org.hamcrest.core.IsNothingMatcher 11 | * @see org.hamcrest.core#anything() 12 | * 13 | * @example 14 | * 15 | * // all fail 16 | * assertThat("the great void", nothing()); 17 | * assertThat(true, nothing()); 18 | * assertThat(false, nothing()); 19 | * assertThat({}, nothing()); 20 | * assertThat(123, nothing()); 21 | * 22 | * 23 | * @author Drew Bourne 24 | */ 25 | public function nothing(message:String = null):Matcher 26 | { 27 | return new IsNothingMatcher(message); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/core/throws.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.core 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.object.instanceOf; 5 | 6 | /** 7 | * Matches if the item under test is a Function, and throws an Error matching the given Matcher. 8 | * 9 | * @see org.hamcrest.core.ThrowsMatcher 10 | * 11 | * @example 12 | * 13 | * assertThat(function():void { 14 | * systemUnderTest.methodCall(given, bad, args); 15 | * }, throws(allOf( 16 | * instanceOf(OhNoItsAnError), 17 | * hasPropertyWithValue("message", "oh no")))); 18 | * 19 | * 20 | * @author Drew Bourne 21 | */ 22 | public function throws(error:Object):Matcher 23 | { 24 | if (error is Class) 25 | { 26 | return throws(instanceOf(error as Class)); 27 | } 28 | else if (error is Matcher) 29 | { 30 | return new ThrowsMatcher(error as Matcher); 31 | } 32 | else 33 | { 34 | throw new ArgumentError("error must be either Class or Matcher"); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/date/DateEqualMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.date 2 | { 3 | import org.hamcrest.Description; 4 | import org.hamcrest.TypeSafeMatcher; 5 | 6 | /** 7 | * Matches a Date equal to the expected Date 8 | * 9 | * @see org.hamcrest.date#dateEqual() 10 | */ 11 | public class DateEqualMatcher extends TypeSafeMatcher 12 | { 13 | private var _compareDate:Date; 14 | 15 | /** 16 | * Constructor. 17 | * 18 | * @param value Expected Date the matched value must be exactly equal to 19 | */ 20 | public function DateEqualMatcher(value:Date) 21 | { 22 | super(Date); 23 | _compareDate = value; 24 | } 25 | 26 | /** 27 | * @inheritDoc 28 | */ 29 | override public function matchesSafely(value:Object):Boolean 30 | { 31 | return ((value as Date).time == _compareDate.time); 32 | } 33 | 34 | /** 35 | * @inheritDoc 36 | */ 37 | override public function describeMismatch(item:Object, mismatchDescription:Description):void 38 | { 39 | mismatchDescription 40 | .appendValue(item) 41 | .appendText(" is not the same as ") 42 | .appendValue(_compareDate); 43 | } 44 | 45 | /** 46 | * @inheritDoc 47 | */ 48 | override public function describeTo(description:Description):void 49 | { 50 | description.appendText("a date equal to ").appendValue(_compareDate); 51 | } 52 | 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/date/dateAfter.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.date 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches if the date item is after the given date. 7 | * 8 | * @param value Date the matched number must be after. 9 | * @return Matcher 10 | * 11 | * @see org.hamcrest.date.DateAfterMatcher 12 | * 13 | * @example 14 | * 15 | * assertThat( new Date(), dateAfter( new Date( 1920, 1, 1))); 16 | * > 17 | */ 18 | public function dateAfter(value:Date):Matcher 19 | { 20 | return new DateAfterMatcher(value); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/date/dateAfterOrEqual.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.date 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.core.describedAs; 5 | 6 | /** 7 | * Matches if the date item is after or equal to the given date. 8 | * 9 | * @param value Date the matched number must be after or equal to. 10 | * @return Matcher 11 | * 12 | * @see org.hamcrest.date.DateAfterMatcher 13 | * 14 | * @example 15 | * 16 | * assertThat( new Date(), dateAfterOrEqual( new Date( 1920, 1, 1))); 17 | * 18 | */ 19 | public function dateAfterOrEqual(value:Date):Matcher 20 | { 21 | var afterMatcher:DateAfterMatcher = new DateAfterMatcher(value, true); 22 | return describedAs("a date after or equal to %0", afterMatcher, value); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/date/dateBefore.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.date 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches if the date item is before the given date. 7 | * 8 | * @param value Date the matched number must be before. 9 | * @return Matcher 10 | * 11 | * @see org.hamcrest.date.DateBeforeMatcher 12 | * 13 | * @example 14 | * 15 | * assertThat( new Date(1920, 1, 1), dateBefore( new Date() ) ); 16 | * 17 | */ 18 | public function dateBefore(value:Date):Matcher 19 | { 20 | return new DateBeforeMatcher(value); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/date/dateBeforeOrEqual.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.date 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.core.describedAs; 5 | 6 | /** 7 | * Matches if the date item is before or equal to the given date. 8 | * 9 | * @param value Date the matched number must be before or equal to. 10 | * @return Matcher 11 | * 12 | * @see org.hamcrest.date.DateBeforeMatcher 13 | * 14 | * @example 15 | * 16 | * assertThat( new Date(1920, 1, 1), dateBeforeOrEqual( new Date() ) ); 17 | * 18 | */ 19 | public function dateBeforeOrEqual(value:Date):Matcher 20 | { 21 | var beforeMatcher:DateBeforeMatcher = new DateBeforeMatcher(value, true); 22 | return describedAs("a date before or equal to %0", beforeMatcher, value); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/date/dateEqual.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.date 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches if the date item is equal to the given date. 7 | * 8 | * @param value Date the matched item must be equal. 9 | * @return Matcher 10 | * 11 | * @see org.hamcrest.date.DateEqualMatcher 12 | * 13 | * @example 14 | * 15 | * assertThat(new Date(), dateEqual( new Date() )); 16 | * 17 | */ 18 | public function dateEqual(value:Date):Matcher 19 | { 20 | return new DateEqualMatcher(value); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/number/IsNotANumberMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.number 2 | { 3 | import org.hamcrest.Description; 4 | import org.hamcrest.TypeSafeMatcher; 5 | 6 | /** 7 | * Matches a value if it is NaN. 8 | * 9 | * @see org.hamcrest.number.isNotANumber() 10 | * 11 | * @example 12 | * 13 | * assertThat(0/0, isNotANumber()); 14 | * 15 | * 16 | * @author Drew Bourne 17 | */ 18 | public class IsNotANumberMatcher extends TypeSafeMatcher 19 | { 20 | /** 21 | * Constructor. 22 | */ 23 | public function IsNotANumberMatcher() 24 | { 25 | super(Number); 26 | } 27 | 28 | /** 29 | * Matches if isNaN(item) is true 30 | */ 31 | override public function matchesSafely(item:Object):Boolean 32 | { 33 | return isNaN(item as Number); 34 | } 35 | 36 | /** 37 | * @inheritDoc 38 | */ 39 | override public function describeTo(description:Description):void 40 | { 41 | description.appendText("NaN"); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/number/IsNumberMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.number 2 | { 3 | import org.hamcrest.Description; 4 | import org.hamcrest.TypeSafeMatcher; 5 | 6 | /** 7 | * Matches a value if it is a Number, excluding NaN, Infinity and -Infinity. 8 | * 9 | * @see org.hamcrest.number.isNumber() 10 | * 11 | * @example 12 | * 13 | * // passes 14 | * assertThat(0, isNumber()); 15 | * 16 | * // fails 17 | * assertThat(NaN, isNumber()); 18 | * assertThat(Infinity, isNumber()); 19 | * assertThat(-Infinity, isNumber()); 20 | * 21 | * 22 | * @author Drew Bourne 23 | */ 24 | public class IsNumberMatcher extends TypeSafeMatcher 25 | { 26 | /** 27 | * Constructor. 28 | */ 29 | public function IsNumberMatcher() 30 | { 31 | super(Number); 32 | } 33 | 34 | override public function matchesSafely(item:Object):Boolean 35 | { 36 | return !isNaN(item as Number) 37 | && item != Number.POSITIVE_INFINITY 38 | && item != Number.NEGATIVE_INFINITY; 39 | } 40 | 41 | override public function describeTo(description:Description):void 42 | { 43 | description.appendText("a Number"); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/number/atLeast.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.number 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.core.describedAsWithMismatch; 5 | 6 | /** 7 | * Matches if the item is greater than or equal to the given value 8 | * 9 | * @param value Number the matched item must be greater than. 10 | * @return Matcher 11 | * 12 | * @see org.hamcrest.number.IsGreaterThanMatcher 13 | * 14 | * @example 15 | * 16 | * assertThat(5, atLeat(4)); 17 | * 18 | * 19 | * @author Drew Bourne 20 | */ 21 | public function atLeast(value:Number):Matcher 22 | { 23 | return describedAsWithMismatch( 24 | "at least %0", 25 | "was %0", 26 | greaterThanOrEqualTo(value), 27 | value); 28 | } 29 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/number/atMost.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.number 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.core.describedAsWithMismatch; 5 | 6 | /** 7 | * Matches if the item is less than the given value. 8 | * 9 | * @param value Number the matched item must be less than. 10 | * @return Matcher 11 | * 12 | * @see org.hamcrest.number.IsLessThanMatcher 13 | * 14 | * @example 15 | * 16 | * assertThat(3, lessThan(4)); 17 | * 18 | * 19 | * @author Drew Bourne 20 | */ 21 | public function atMost(value:Number):Matcher 22 | { 23 | return describedAsWithMismatch( 24 | "at most %0", 25 | "was %0", 26 | lessThanOrEqualTo(value), 27 | value); 28 | } 29 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/number/closeTo.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.number 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches if a value is within +/- the delta value from the given value. 7 | * 8 | * @param value 9 | * @param delta 10 | * 11 | * @see org.hamcrest.number.IsCloseToMatcher 12 | * 13 | * @example 14 | * 15 | * assertThat(3, closeTo(4, 1)); 16 | * // passes 17 | * 18 | * assertThat(3, closeTo(5, 0.5)); 19 | * // fails 20 | * 21 | * assertThat(4.5, closeTo(5, 0.5)); 22 | * // passes 23 | * 24 | * 25 | * @author Drew Bourne 26 | */ 27 | public function closeTo(value:Number, delta:Number):Matcher 28 | { 29 | return new IsCloseToMatcher(value, delta); 30 | } 31 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/number/greaterThan.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.number 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches if the item is greater than the given value. 7 | * 8 | * @param value Number the matched item must be greater than. 9 | * @return Matcher 10 | * 11 | * @see org.hamcrest.number.IsGreaterThanMatcher 12 | * 13 | * @example 14 | * 15 | * assertThat(5, greaterThan(4)); 16 | * 17 | * 18 | * @author Drew Bourne 19 | */ 20 | public function greaterThan(value:Number):Matcher 21 | { 22 | return new IsGreaterThanMatcher(value, false); 23 | } 24 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/number/greaterThanOrEqualTo.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.number 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.core.anyOf; 5 | import org.hamcrest.core.describedAs; 6 | import org.hamcrest.object.equalTo; 7 | 8 | /** 9 | * Matches if the item is greater than or equal to the given value. 10 | * 11 | * @param value Number the matched item must be greater than or equal to. 12 | * @return Matcher 13 | * 14 | * @see org.hamcrest.number.IsGreaterThanMatcher 15 | * 16 | * @example 17 | * 18 | * assertThat(4, greaterThanOrEqualTo(4)); 19 | * 20 | * 21 | * @author Drew Bourne 22 | */ 23 | public function greaterThanOrEqualTo(value:Number):Matcher 24 | { 25 | return new IsGreaterThanMatcher(value, true); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/number/isNotANumber.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.number 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches a value if it is NaN. 7 | * 8 | * @see org.hamcrest.number.IsNotANumberMatcher 9 | * 10 | * @example 11 | * 12 | * assertThat(0/0, isNotANumber()); 13 | * 14 | * 15 | * @author Drew Bourne 16 | */ 17 | public function isNotANumber():Matcher 18 | { 19 | return new IsNotANumberMatcher(); 20 | } 21 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/number/isNumber.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.number 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.core.allOf; 5 | import org.hamcrest.core.describedAs; 6 | import org.hamcrest.core.not; 7 | import org.hamcrest.object.instanceOf; 8 | 9 | /** 10 | * Matches a value if it is a Number, excluding NaN, Infinity and -Infinity. 11 | * 12 | * @see org.hamcrest.number.IsNumberMatcher 13 | * 14 | * @example 15 | * 16 | * // passes 17 | * assertThat(0, isNumber()); 18 | * 19 | * // fails 20 | * assertThat(NaN, isNumber()); 21 | * assertThat(Infinity, isNumber()); 22 | * assertThat(-Infinity, isNumber()); 23 | * 24 | * 25 | * @author Drew Bourne 26 | */ 27 | public function isNumber():Matcher 28 | { 29 | return new IsNumberMatcher(); 30 | } 31 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/number/lessThan.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.number 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches if the item is less than the given value. 7 | * 8 | * @param value Number the matched item must be less than. 9 | * @return Matcher 10 | * 11 | * @see org.hamcrest.number.IsLessThanMatcher 12 | * 13 | * @example 14 | * 15 | * assertThat(3, lessThan(4)); 16 | * 17 | * 18 | * @author Drew Bourne 19 | */ 20 | public function lessThan(value:Number):Matcher 21 | { 22 | return new IsLessThanMatcher(value, false); 23 | } 24 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/number/lessThanOrEqualTo.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.number 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.core.anyOf; 5 | import org.hamcrest.core.describedAs; 6 | import org.hamcrest.object.equalTo; 7 | 8 | /** 9 | * Matches if the item is less than or equal to the given value. 10 | * 11 | * @param value Number the matched item must be less than or equal to. 12 | * @return Matcher 13 | * 14 | * @see org.hamcrest.number.IsLessThanMatcher 15 | * 16 | * @example 17 | * 18 | * assertThat(4, lessThanOrEqualTo(4)); 19 | * 20 | * 21 | * @author Drew Bourne 22 | */ 23 | public function lessThanOrEqualTo(value:Number):Matcher 24 | { 25 | return new IsLessThanMatcher(value, true); 26 | } 27 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/IsFalseMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.BaseMatcher; 4 | import org.hamcrest.Description; 5 | 6 | /** 7 | * Matches item if it is false. 8 | * 9 | * When the constructor parameter coerceToBoolean is true 10 | * Then any false-like value will also be matched. These include: null, 11 | * 0, NaN "" (empty string). 12 | * 13 | * @example 14 | * 15 | * assertThat( checkBox.selected, isFalse() ); 16 | * 17 | */ 18 | public class IsFalseMatcher extends BaseMatcher 19 | { 20 | private var _coerceToBoolean:Boolean; 21 | 22 | /** 23 | * Constructor. 24 | * 25 | * @param coerceToBoolean Indicates if the Matcher should coerce the item 26 | * being matched to a Boolean before strictly comparing to false. 27 | */ 28 | public function IsFalseMatcher(coerceToBoolean:Boolean = false) 29 | { 30 | super(); 31 | 32 | _coerceToBoolean = coerceToBoolean; 33 | } 34 | 35 | override public function matches(item:Object):Boolean 36 | { 37 | return _coerceToBoolean 38 | ? Boolean(item) === false 39 | : item === false; 40 | } 41 | 42 | /** 43 | * Description of isFalse(), "is false". 44 | */ 45 | override public function describeTo(description:Description):void 46 | { 47 | description.appendText("is false"); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/IsInstanceOfMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import flash.utils.getQualifiedClassName; 4 | 5 | import org.hamcrest.BaseMatcher; 6 | import org.hamcrest.Description; 7 | 8 | /** 9 | * Matches if the item is an instance of the given type. 10 | * 11 | * @see org.hamcrest.object#instanceOf() 12 | * 13 | * @exmaple 14 | * 15 | * assertThat("waffles", instanceOf(String)); 16 | * 17 | * 18 | * @author Drew Bourne 19 | */ 20 | public class IsInstanceOfMatcher extends BaseMatcher 21 | { 22 | private var _type:Class; 23 | private var _typeName:String; 24 | 25 | /** 26 | * Constructor 27 | * 28 | * @param type Class the item must be an instance of. 29 | */ 30 | public function IsInstanceOfMatcher(type:Class) 31 | { 32 | _type = type; 33 | _typeName = getQualifiedClassName(type); 34 | } 35 | 36 | /** 37 | * @inheritDoc 38 | */ 39 | override public function matches(item:Object):Boolean 40 | { 41 | return item is _type; 42 | } 43 | 44 | /** 45 | * @inheritDoc 46 | */ 47 | override public function describeTo(description:Description):void 48 | { 49 | description.appendText("an instance of ").appendText(_typeName); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/IsInterfaceMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import flash.utils.describeType; 4 | 5 | import org.hamcrest.BaseMatcher; 6 | import org.hamcrest.Description; 7 | 8 | public class IsInterfaceMatcher extends BaseMatcher 9 | { 10 | override public function matches(item:Object):Boolean 11 | { 12 | if (item is Class) 13 | { 14 | var type:XML = describeType(item); 15 | return (type.factory.extendsClass.length() == 0); 16 | } 17 | 18 | return false; 19 | } 20 | 21 | override public function describeTo(description:Description):void 22 | { 23 | description.appendText("an interface"); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/IsNullMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.BaseMatcher; 4 | import org.hamcrest.Description; 5 | 6 | /** 7 | * Matches if the item is null 8 | * 9 | * @see org.hamcrest.object#nullValue() 10 | * @see org.hamcrest.object#notNullValue() 11 | * 12 | * @author Drew Bourne 13 | */ 14 | public class IsNullMatcher extends BaseMatcher 15 | { 16 | /** 17 | * @inheritDoc 18 | */ 19 | override public function matches(item:Object):Boolean 20 | { 21 | return item == null; 22 | } 23 | 24 | /** 25 | * @inheritDoc 26 | */ 27 | override public function describeTo(description:Description):void 28 | { 29 | description.appendText("null"); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/IsSameMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.BaseMatcher; 4 | import org.hamcrest.Description; 5 | 6 | /** 7 | * Matches an item if it is === to the given value. 8 | * 9 | * @see org.hamcrest#sameInstance() 10 | * 11 | * @author Drew Bourne 12 | */ 13 | public class IsSameMatcher extends BaseMatcher 14 | { 15 | private var _value:Object; 16 | 17 | /** 18 | * Constructor 19 | * 20 | * @param value Object the item must be === to 21 | */ 22 | public function IsSameMatcher(value:Object) 23 | { 24 | _value = value; 25 | } 26 | 27 | /** 28 | * @inheritDoc 29 | */ 30 | override public function matches(item:Object):Boolean 31 | { 32 | return item === _value; 33 | } 34 | 35 | /** 36 | * @inheritDoc 37 | */ 38 | override public function describeTo(description:Description):void 39 | { 40 | description.appendText("same instance ").appendValue(_value); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/IsStrictlyEqualMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.BaseMatcher; 4 | import org.hamcrest.Description; 5 | 6 | /** 7 | * Checks the item being matched are strictly equal (===). 8 | * 9 | * @see org.hamcrest.object#strictlyEqualTo() 10 | * 11 | * @example 12 | * 13 | * var o1:Object = {}; 14 | * var o2:Object = {}; 15 | * assertThat(o1, strictlyEqualTo(o1")); 16 | * assertThat(o1, not(strictlyEqualTo(o2))); 17 | * 18 | * 19 | * @author Drew Bourne 20 | */ 21 | public class IsStrictlyEqualMatcher extends BaseMatcher 22 | { 23 | private var _value:Object; 24 | 25 | /** 26 | * Constructor 27 | * 28 | * @param value Object the item being matched must be equal to 29 | */ 30 | public function IsStrictlyEqualMatcher(value:Object) 31 | { 32 | super(); 33 | 34 | _value = value; 35 | } 36 | 37 | /** 38 | * @inheritDoc 39 | */ 40 | override public function matches(item:Object):Boolean 41 | { 42 | return _value === item; 43 | } 44 | 45 | /** 46 | * @inheritDoc 47 | */ 48 | override public function describeTo(description:Description):void 49 | { 50 | description.appendValue(_value); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/IsTrueMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.BaseMatcher; 4 | import org.hamcrest.Description; 5 | 6 | /** 7 | * Matches item if it is true. 8 | * 9 | * When the constructor parameter coerceToBoolean is true 10 | * Then any true-like value will also be matched. This excludes: null, 11 | * 0, NaN "" (empty string). 12 | * 13 | * @example 14 | * 15 | * assertThat( checkBox.selected, isTrue() ); 16 | * 17 | * 18 | * @author Drew Bourne 19 | */ 20 | public class IsTrueMatcher extends BaseMatcher 21 | { 22 | private var _coerceToBoolean:Boolean; 23 | 24 | /** 25 | * Constructor 26 | * 27 | * @param coerceToBoolean Indicates if the Matcher should coerce the item 28 | * being matched to a Boolean before strictly comparing to false. 29 | */ 30 | public function IsTrueMatcher(coerceToBoolean:Boolean = false) 31 | { 32 | super(); 33 | 34 | _coerceToBoolean = coerceToBoolean; 35 | } 36 | 37 | /** 38 | * 39 | */ 40 | override public function matches(item:Object):Boolean 41 | { 42 | return _coerceToBoolean 43 | ? Boolean(item) === true 44 | : item === true; 45 | } 46 | 47 | /** 48 | * Description of isTrue(), "is true". 49 | */ 50 | override public function describeTo(description:Description):void 51 | { 52 | description.appendText("is true"); 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/equalTo.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Checks the item being matched is equal (==). 7 | * 8 | *
    9 | *
  • Numbers match if they are equal (==)
  • 10 | *
  • Numbers match if they are both NaN.
  • 11 | *
  • nulls match.
  • 12 | *
  • Arrays match if they are the same length and each item is equal. 13 | * Checked recursively for child arrays.
  • 14 | *
15 | * 16 | * @see org.hamcrest.object.IsEqualMatcher 17 | * 18 | * @example 19 | * 20 | * assertThat("hi", equalTo("hi")); 21 | * assertThat("bye", not(equalTo("hi"))); 22 | * 23 | * 24 | * @author Drew Bourne 25 | */ 26 | public function equalTo(value:Object):Matcher 27 | { 28 | return new IsEqualMatcher(value); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/hasProperties.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.core.allOf; 5 | 6 | /** 7 | * Matches if item.hasOwnProperty(propertyName) is true, and the value 8 | * for that property matches the valueMatcher for each of the key-value pairs in the given object. 9 | * 10 | * @see org.hamcrest.object#hasPropertyWithValue() 11 | * 12 | * @example 13 | * 14 | * var event:Event = new Event(Event.COMPLETE, true, false); 15 | * assertThat(event, hasProperties({ 16 | * type: equalTo(Event.COMPLETE), 17 | * bubbles: true // automatically wrapped in equalTo() 18 | * cancelable: anything() 19 | * })) 20 | * 21 | * 22 | * @author Drew Bourne 23 | */ 24 | public function hasProperties(properties:Object):Matcher 25 | { 26 | return new HasPropertiesMatcher(properties); 27 | 28 | // var matchers:Array = []; 29 | // for (var field:String in object) 30 | // { 31 | // var value:Object = object[field]; 32 | // var valueMatcher:Matcher = value is Matcher ? value as Matcher : equalTo(value); 33 | // var propertyMatcher:Matcher = hasPropertyWithValue(field, valueMatcher); 34 | // matchers.push(propertyMatcher); 35 | // } 36 | // 37 | // // TODO determine if this is still the case 38 | // // NB anonymous objects seem to be iterating their fields in reverse order 39 | // return allOf.apply(null, matchers.reverse()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/hasProperty.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches if item.hasOwnProperty(propertyName) is true. 7 | * 8 | * @param propertyName Name of the property the item being matched must have. 9 | * @param valueOrMatcher Optional value or Matcher to compare the property value against. 10 | * 11 | * @see org.hamcrest.object#hasPropertyWithValue() 12 | * @see org.hamcrest.object#hasPropertyChain() 13 | * @see org.hamcrest.object.HasPropertyMatcher 14 | * @see org.hamcrest.object.HasPropertyWithValueMatcher 15 | * 16 | * @example 17 | * 18 | * assertThat({ id: 1234, data: null }, hasProperty("data")); 19 | * assertThat({ id: 1234, data: null }, hasProperty("data", nullValue())); 20 | * 21 | * 22 | * @author Drew Bourne 23 | */ 24 | public function hasProperty(propertyName:String, ... rest):Matcher 25 | { 26 | switch (rest.length) 27 | { 28 | case 0: 29 | return new HasPropertyMatcher(propertyName); 30 | case 1: 31 | return hasPropertyWithValue(propertyName, rest[0]); 32 | default: 33 | throw new ArgumentError('hasProperty accepts 1 or 2 arguments only.'); 34 | } 35 | 36 | return null; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/hasPropertyChain.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches an object with properties for each link in the given property 7 | * chain, optionally checking for an expected value. 8 | * 9 | * @see org.hamcrest.object#hasProperty() 10 | * @see org.hamcrest.object#hasPropertyWithValue() 11 | * @see org.hamcrest.object.HasPropertyChainMatcher 12 | * 13 | * @example 14 | * 15 | * assertThat({ one: { two: 3 } }, hasPropertyChain("one.two")); 16 | * assertThat({ one: { two: 3 } }, hasPropertyChain("one.two", equalTo(3))); 17 | * 18 | * 19 | * @author Drew Bourne 20 | */ 21 | public function hasPropertyChain(propertyChain:Object, valueOrMatcher:Object = null):Matcher 22 | { 23 | var valueMatcher:Matcher 24 | = valueOrMatcher is Matcher 25 | ? valueOrMatcher as Matcher 26 | : valueOrMatcher != null 27 | ? equalTo(valueOrMatcher) 28 | : null; 29 | 30 | return new HasPropertyChainMatcher(propertyChain, valueMatcher); 31 | } 32 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/hasPropertyWithValue.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches if item.hasOwnProperty(propertyName) is true, and the value 7 | * for that property matches the given valueMatcher. 8 | * 9 | * @param propertyName Name of the property the item being matched must have. 10 | * 11 | * @see org.hamcrest.object#hasProperty() 12 | * @see org.hamcrest.object#hasPropertyChain() 13 | * @see org.hamcrest.object.HasPropertyWithValueMatcher 14 | * 15 | * @example 16 | * 17 | * assertThat({ id: 1234, data: [1, 2, 3] }, hasPropertyWithValue("data", everyItem(isA(Number)))); 18 | * 19 | * 20 | * @author Drew Bourne 21 | */ 22 | public function hasPropertyWithValue(propertyName:String, valueOrMatcher:Object):Matcher 23 | { 24 | var valueMatcher:Matcher 25 | = valueOrMatcher is Matcher 26 | ? valueOrMatcher as Matcher 27 | : equalTo(valueOrMatcher); 28 | 29 | return new HasPropertyWithValueMatcher(propertyName, valueMatcher); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/instanceOf.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches if the item is an instance of the given type. 7 | * 8 | * @param type Class the item must be an instance of 9 | * 10 | * @see org.hamcrest.object.IsInstanceOfMatcher 11 | * 12 | * @exmaple 13 | * 14 | * assertThat("waffles", instanceOf(String)); 15 | * 16 | * 17 | * @author Drew Bourne 18 | */ 19 | public function instanceOf(type:Class):Matcher 20 | { 21 | return new IsInstanceOfMatcher(type); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/isFalse.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches item if it is strictly equal to false. 7 | * 8 | * @see org.hamcrest.object#isTruthy() for a non-strict falsiness matcher. 9 | * 10 | * @example 11 | * 12 | * assertThat( checkBox.selected, isFalse() ); 13 | * 14 | * 15 | * @author Drew Bourne 16 | */ 17 | public function isFalse():Matcher 18 | { 19 | return new IsFalseMatcher(); 20 | } 21 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/isFalsey.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches item if it can be coerced to false. 7 | * 8 | * @see org.hamcrest.object#isTruthy() for a strict falsiness matcher. 9 | * 10 | * @example 11 | * 12 | * assertThat( input.text, isFalsey() ); 13 | * 14 | * 15 | * @author Drew Bourne 16 | */ 17 | public function isFalsey():Matcher 18 | { 19 | return new IsFalseMatcher(true); 20 | } 21 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/isInterface.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches a Class reference that defines an interface. 7 | * 8 | * @example 9 | * 10 | * assertThat(IExternalizable, isInterface()); 11 | * 12 | */ 13 | public function isInterface():Matcher 14 | { 15 | return new IsInterfaceMatcher(); 16 | } 17 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/isNotNull.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.core.not; 5 | 6 | /** 7 | * Matches if the item is not null 8 | * 9 | * @see org.hamcrest.object.IsNullMatcher 10 | * @see org.hamcrest.object#isNull() 11 | * 12 | * @example 13 | * 14 | * assertThat({ any: "object" }, isNotNull()); 15 | * 16 | * 17 | * @author Drew Bourne 18 | */ 19 | public function isNotNull():Matcher 20 | { 21 | return not(isNull()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/isNull.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches if the item is null 7 | * 8 | * @see org.hamcrest.object.IsNullMatcher 9 | * 10 | * @example 11 | * 12 | * assertThat(null, isNull()); 13 | * 14 | * 15 | * @author Drew Bourne 16 | */ 17 | public function isNull():Matcher 18 | { 19 | return new IsNullMatcher(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/isTrue.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches item if it is strictly equal to true. 7 | * 8 | * @see org.hamcrest.object#isTruthy() for a non-strict truthiness matcher. 9 | * 10 | * @example 11 | * 12 | * assertThat( checkBox.selected, isTrue() ); 13 | * 14 | * 15 | * @author Drew Bourne 16 | */ 17 | public function isTrue():Matcher 18 | { 19 | return new IsTrueMatcher(); 20 | } 21 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/isTruthy.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches item if it can be coerced to true. 7 | * 8 | * @see org.hamcrest.object#isTrue() for a strict truthiness matcher. 9 | * 10 | * @example 11 | * 12 | * assertThat( checkBox.selected, isTruthy() ); 13 | * 14 | * 15 | * @author Drew Bourne 16 | */ 17 | public function isTruthy():Matcher 18 | { 19 | return new IsTrueMatcher(true); 20 | } 21 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/notNullValue.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.core.not; 5 | 6 | /** 7 | * Matches if the item is not null 8 | * 9 | * @see org.hamcrest.object.IsNullMatcher 10 | * @see org.hamcrest.object#nullValue() 11 | * 12 | * @example 13 | * 14 | * assertThat({ any: "object" }, notNullValue()); 15 | * 16 | * 17 | * @author Drew Bourne 18 | */ 19 | public function notNullValue():Matcher 20 | { 21 | return not(nullValue()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/nullOr.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.Matcher; 4 | import org.hamcrest.core.anyOf; 5 | 6 | /** 7 | * Matches either null or the specified matcher or value. 8 | * 9 | * @param matcherOrValue Matcher or value to be wrapped in equalTo(). 10 | * 11 | * @example 12 | * 13 | * assertThat(value, nullOr(3)); 14 | * assertThat(value, nullOr(greaterThan(2)); 15 | * 16 | */ 17 | public function nullOr(matcherOrValue:*):Matcher 18 | { 19 | var matcher:Matcher = matcherOrValue is Matcher 20 | ? matcherOrValue 21 | : equalTo(matcherOrValue); 22 | 23 | return anyOf(nullValue(), matcher); 24 | } 25 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/nullValue.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches if the item is null 7 | * 8 | * @see org.hamcrest.object.IsNullMatcher 9 | * 10 | * @example 11 | * 12 | * assertThat(null, nullValue()); 13 | * 14 | * 15 | * @author Drew Bourne 16 | */ 17 | public function nullValue():Matcher 18 | { 19 | return new IsNullMatcher(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/sameInstance.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches an item if it is === to the given value. 7 | * 8 | * @param 9 | * 10 | * @see org.hamcrest.object.IsSameMatcher 11 | * 12 | * @example 13 | * 14 | * assertThat(3, sameInstance(3)); 15 | * 16 | * var event:Event = new Event("example"): 17 | * assertThat(event, sameInstance(event)); 18 | * assertThat(event, not(sameInstance(new Event("example")))); 19 | * 20 | * 21 | * @author Drew Bourne 22 | */ 23 | public function sameInstance(value:Object):Matcher 24 | { 25 | return new IsSameMatcher(value); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/object/strictlyEqualTo.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.object 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Checks the item being matched are strictly equal (===). 7 | * 8 | * @see org.hamcrest.object.IsStrictlyEqualMatcher 9 | * 10 | * @example 11 | * 12 | * var o1:Object = {}; 13 | * var o2:Object = {}; 14 | * assertThat(o1, strictlyEqualTo(o1")); 15 | * assertThat(o1, not(strictlyEqualTo(o2))); 16 | * 17 | * 18 | * @author Drew Bourne 19 | */ 20 | public function strictlyEqualTo(value:Object):Matcher 21 | { 22 | return new IsStrictlyEqualMatcher(value); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/text/ContainsStringsMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.text 2 | { 3 | import org.hamcrest.BaseMatcher; 4 | import org.hamcrest.Description; 5 | import org.hamcrest.DiagnosingMatcher; 6 | 7 | public class ContainsStringsMatcher extends DiagnosingMatcher 8 | { 9 | private var _strings:Array; 10 | 11 | public function ContainsStringsMatcher(strings:Array) 12 | { 13 | super(); 14 | 15 | _strings = strings || []; 16 | } 17 | 18 | override public function describeTo(description:Description):void 19 | { 20 | description.appendText("a String containing all of ").appendValue(_strings); 21 | } 22 | 23 | override protected function matchesOrDescribesMismatch(item:Object, description:Description):Boolean 24 | { 25 | var target:String = item as String; 26 | var missingStrings:Array = []; 27 | var result:Boolean = true; 28 | 29 | if (item is String) 30 | { 31 | for each (var string:String in _strings) 32 | { 33 | if (target.indexOf(string) == -1) 34 | { 35 | missingStrings[missingStrings.length] = string; 36 | } 37 | } 38 | } 39 | 40 | if (missingStrings.length > 0) 41 | { 42 | result = false; 43 | 44 | description 45 | .appendText("was ") 46 | .appendValue(item) 47 | .appendText(" did not contain ") 48 | .appendValue(missingStrings); 49 | } 50 | 51 | return result; 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/text/EmptyStringMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.text 2 | { 3 | import org.hamcrest.Description; 4 | import org.hamcrest.TypeSafeDiagnosingMatcher; 5 | import org.hamcrest.TypeSafeMatcher; 6 | 7 | /** 8 | * Matches a String if it is zero-length, or contains only whitespace. 9 | * 10 | * @see org.hamcrest.text#emptyString() 11 | * 12 | * @example 13 | * 14 | * assertThat(textInput.text, not(emptyString())); 15 | * 16 | * 17 | * @author Drew Bourne 18 | */ 19 | public class EmptyStringMatcher extends TypeSafeMatcher 20 | { 21 | /** 22 | * Constructor 23 | */ 24 | public function EmptyStringMatcher() 25 | { 26 | super(String); 27 | } 28 | 29 | /** 30 | * Matches a String that is zero length or contains only whitespace. 31 | */ 32 | override public function matchesSafely(item:Object):Boolean 33 | { 34 | var string:String = String(item); 35 | return string.length == 0 || string.match(/^[\s]+$/); 36 | } 37 | 38 | /** 39 | * Describes this matcher as "an empty String". 40 | */ 41 | override public function describeTo(description:Description):void 42 | { 43 | description.appendText("an empty String"); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/text/RegExpMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.text 2 | { 3 | import org.hamcrest.BaseMatcher; 4 | 5 | /** 6 | * Matches a String if it matches the RegExp 7 | * 8 | * @param re RegExp to match with. 9 | * 10 | * @see org.hamcrest.text#re() 11 | * 12 | * @example 13 | * 14 | * assertThat("has some whitespace", "The quick brown fox", re(/\s+/)); 15 | * 16 | * 17 | * @author Drew Bourne 18 | */ 19 | public class RegExpMatcher extends SubstringMatcher 20 | { 21 | private var _pattern:RegExp; 22 | 23 | /** 24 | * Constructor 25 | * 26 | * @param substring Substring to search for 27 | */ 28 | public function RegExpMatcher(pattern:RegExp) 29 | { 30 | _pattern = pattern; 31 | 32 | super(_pattern.toString()); 33 | } 34 | 35 | /** 36 | * @inheritDoc 37 | */ 38 | override protected function evaluateSubstringOf(s:String):Boolean 39 | { 40 | return _pattern.test(s); 41 | } 42 | 43 | /** 44 | * @inheritDoc 45 | */ 46 | override protected function relationship():String 47 | { 48 | return "matching"; 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/text/StringContainsMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.text 2 | { 3 | 4 | /** 5 | * Matches a String if it contains the given substring. 6 | * 7 | * @see org.hamcrest.text#containsString() 8 | * @see org.hamcrest.text.SubstringMatcher 9 | * 10 | * @author Drew Bourne 11 | */ 12 | public class StringContainsMatcher extends SubstringMatcher 13 | { 14 | /** 15 | * Constructor 16 | * 17 | * @param substring Substring to search for 18 | * @param ignoreCase Indicates if the match should ignore the case of the substring 19 | */ 20 | public function StringContainsMatcher(substring:String, ignoreCase:Boolean = false) 21 | { 22 | super(substring, ignoreCase); 23 | } 24 | 25 | /** 26 | * @inheritDoc 27 | */ 28 | override protected function evaluateSubstringOf(s:String):Boolean 29 | { 30 | if (ignoreCase) 31 | { 32 | return s.toLowerCase().indexOf(substring.toLowerCase()) >= 0; 33 | } 34 | 35 | return s.indexOf(substring) >= 0; 36 | } 37 | 38 | /** 39 | * @inheritDoc 40 | */ 41 | override protected function relationship():String 42 | { 43 | return "containing"; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/text/StringEndsWithMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.text 2 | { 3 | 4 | /** 5 | * Matches a String if it ends with the given value 6 | * 7 | * @see org.hamcrest.text#endsWith() 8 | * @see org.hamcrest.text.SubstringMatcher 9 | * 10 | * @author Drew Bourne 11 | */ 12 | public class StringEndsWithMatcher extends SubstringMatcher 13 | { 14 | /** 15 | * Constructor 16 | * 17 | * @param substring String to search for 18 | * @param ignoreCase Indicates if the match should ignore the case of the substring 19 | */ 20 | public function StringEndsWithMatcher(substring:String, ignoreCase:Boolean = false) 21 | { 22 | super(substring, ignoreCase); 23 | } 24 | 25 | /** 26 | * @inheritDoc 27 | */ 28 | override protected function evaluateSubstringOf(s:String):Boolean 29 | { 30 | return (new RegExp(substring + '$', ignoreCase ? 'i' : null)).test(s); 31 | } 32 | 33 | /** 34 | * @inheritDoc 35 | */ 36 | override protected function relationship():String 37 | { 38 | return "ending with"; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/text/StringStartsWithMatcher.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.text 2 | { 3 | 4 | /** 5 | * Matches a String if it starts with the given value 6 | * 7 | * @see org.hamcrest.text#endsWith() 8 | * @see org.hamcrest.text.SubstringMatcher 9 | * 10 | * @author Drew Bourne 11 | */ 12 | public class StringStartsWithMatcher extends SubstringMatcher 13 | { 14 | /** 15 | * Constructor 16 | * 17 | * @param substring String to search for 18 | * @param ignoreCase Indicates if the match should ignore the case of the substring 19 | */ 20 | public function StringStartsWithMatcher(substring:String, ignoreCase:Boolean = false) 21 | { 22 | super(substring, ignoreCase); 23 | } 24 | 25 | /** 26 | * @inheritDoc 27 | */ 28 | override protected function evaluateSubstringOf(s:String):Boolean 29 | { 30 | return (new RegExp('^' + substring, ignoreCase ? 'i' : null)).test(s); 31 | } 32 | 33 | /** 34 | * @inheritDoc 35 | */ 36 | override protected function relationship():String 37 | { 38 | return "starting with"; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/text/containsString.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.text 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches a String if it contains the given substring. 7 | * 8 | * @param substring String to search for 9 | * 10 | * @see org.hamcrest.text.StringContainsMatcher 11 | * 12 | * @example 13 | * 14 | * assertThat("The quick brown fox", containsString("fox")); 15 | * 16 | * 17 | * @author Drew Bourne 18 | */ 19 | public function containsString(substring:String, ignoreCase:Boolean = false):Matcher 20 | { 21 | return new StringContainsMatcher(substring, ignoreCase); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/text/containsStrings.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.text 2 | { 3 | import org.hamcrest.Description; 4 | import org.hamcrest.Matcher; 5 | import org.hamcrest.StringDescription; 6 | import org.hamcrest.core.allOf; 7 | import org.hamcrest.core.describedAs; 8 | 9 | /** 10 | * Matches a String if it contains all of the given substring. 11 | * 12 | * @param ...strings Array of Strings to search for. 13 | * 14 | * @see org.hamcrest.text.StringContainsMatcher 15 | * 16 | * @example 17 | * 18 | * assertThat("The quick brown fox", containsStrings("quick", "fox")); 19 | * assertThat("The quick brown fox", containsStrings(["quick", "fox"])); 20 | * 21 | * 22 | * @author Drew Bourne 23 | */ 24 | public function containsStrings(...rest):Matcher 25 | { 26 | var strings:Array = rest; 27 | 28 | if (rest.length == 1 && rest[0] is Array) 29 | { 30 | strings = rest[0]; 31 | } 32 | 33 | return new ContainsStringsMatcher(strings); 34 | } 35 | } -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/text/emptyString.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.text 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches a String if it is zero-length, or contains only whitespace. 7 | * 8 | * @see org.hamcrest.text.EmptyStringMatcher 9 | * 10 | * @example 11 | * 12 | * assertThat(textInput.text, not(emptyString())); 13 | * 14 | * 15 | * @author Drew Bourne 16 | */ 17 | public function emptyString():Matcher 18 | { 19 | // return describedAs("an empty String", 20 | // both(isA(String)).and(anyOf(hasProperty('length', 0), re(/^[\s]+$/)))) 21 | 22 | return new EmptyStringMatcher(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/text/endsWith.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.text 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches a String if it ends with the given substring. 7 | * 8 | * @param substring String to search for 9 | * @param ignoreCase Indicates if the match should ignore the case of the substring 10 | * 11 | * @see org.hamcrest.text.StringEndsWithMatcher 12 | * 13 | * @example 14 | * 15 | * assertThat("The quick brown fox", endsWith("fox")); 16 | * 17 | * 18 | * @author Drew Bourne 19 | */ 20 | public function endsWith(substring:String, ignoreCase:Boolean = false):Matcher 21 | { 22 | return new StringEndsWithMatcher(substring, ignoreCase); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/text/re.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.text 2 | { 3 | import org.hamcrest.Matcher; 4 | 5 | /** 6 | * Matches a String if it matches the RegExp 7 | * 8 | * @param re RegExp to match with. 9 | * 10 | * @see org.hamcrest.text.RegExpMatcher 11 | * 12 | * @example 13 | * 14 | * assertThat("has some whitespace", "The quick brown fox", re(/\s+/)); 15 | * 16 | * 17 | * @author Drew Bourne 18 | */ 19 | public function re(pattern:RegExp):Matcher 20 | { 21 | return new RegExpMatcher(pattern); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /hamcrest/src/org/hamcrest/text/startsWith.as: -------------------------------------------------------------------------------- 1 | package org.hamcrest.text 2 | { 3 | 4 | import org.hamcrest.Matcher; 5 | 6 | /** 7 | * Matches a String if it starts with the given substring. 8 | * 9 | * @param substring String to search for 10 | * @param ignoreCase Indicates if the match should ignore the case of the substring 11 | * 12 | * @see org.hamcrest.text.StringStartsWithMatcher 13 | * 14 | * @example 15 | * 16 | * assertThat("The quick brown fox", startsWith("The")); 17 | * 18 | * 19 | * @author Drew Bourne 20 | */ 21 | public function startsWith(substring:String, ignoreCase:Boolean = false):Matcher 22 | { 23 | return new StringStartsWithMatcher(substring, ignoreCase); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /libs/build/as3-parser-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/libs/build/as3-parser-1.1.jar -------------------------------------------------------------------------------- /libs/build/as3-parser-api-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/libs/build/as3-parser-api-1.1.jar -------------------------------------------------------------------------------- /libs/build/as3-plugin-utils-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/libs/build/as3-plugin-utils-1.1.jar -------------------------------------------------------------------------------- /libs/build/commons-lang-2.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/libs/build/commons-lang-2.4.jar -------------------------------------------------------------------------------- /libs/build/dom4j-1.6.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/libs/build/dom4j-1.6.1.jar -------------------------------------------------------------------------------- /libs/build/flex-pmd-ant-task-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/libs/build/flex-pmd-ant-task-1.1.jar -------------------------------------------------------------------------------- /libs/build/flex-pmd-command-line-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/libs/build/flex-pmd-command-line-1.1.jar -------------------------------------------------------------------------------- /libs/build/flex-pmd-command-line-api-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/libs/build/flex-pmd-command-line-api-1.1.jar -------------------------------------------------------------------------------- /libs/build/flex-pmd-core-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/libs/build/flex-pmd-core-1.1.jar -------------------------------------------------------------------------------- /libs/build/flex-pmd-cpd-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/libs/build/flex-pmd-cpd-1.1.jar -------------------------------------------------------------------------------- /libs/build/flex-pmd-cpd-ant-task-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/libs/build/flex-pmd-cpd-ant-task-1.1.jar -------------------------------------------------------------------------------- /libs/build/flex-pmd-cpd-command-line-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/libs/build/flex-pmd-cpd-command-line-1.1.jar -------------------------------------------------------------------------------- /libs/build/flex-pmd-files-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/libs/build/flex-pmd-files-1.1.jar -------------------------------------------------------------------------------- /libs/build/flex-pmd-metrics-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/libs/build/flex-pmd-metrics-1.1.jar -------------------------------------------------------------------------------- /libs/build/flex-pmd-metrics-ant-task-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/libs/build/flex-pmd-metrics-ant-task-1.1.jar -------------------------------------------------------------------------------- /libs/build/flex-pmd-metrics-command-line-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/libs/build/flex-pmd-metrics-command-line-1.1.jar -------------------------------------------------------------------------------- /libs/build/flex-pmd-ruleset-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/libs/build/flex-pmd-ruleset-1.1.jar -------------------------------------------------------------------------------- /libs/build/flex-pmd-ruleset-api-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/libs/build/flex-pmd-ruleset-api-1.1.jar -------------------------------------------------------------------------------- /libs/build/flexUnitTasks-4.0.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/libs/build/flexUnitTasks-4.0.0.jar -------------------------------------------------------------------------------- /libs/build/jsap-2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/libs/build/jsap-2.1.jar -------------------------------------------------------------------------------- /libs/build/plexus-utils-1.0.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/libs/build/plexus-utils-1.0.2.jar -------------------------------------------------------------------------------- /libs/build/pmd-4.2.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drewbourne/hamcrest-as3/7d06e2b877599ec9384683aba74581aa465079b8/libs/build/pmd-4.2.5.jar -------------------------------------------------------------------------------- /version.properties: -------------------------------------------------------------------------------- 1 | build.groupId=hamcrest-as3 2 | build.artifactId=hamcrest-as3 3 | build.version=1.2.0 4 | build.finalName=${build.artifactId}-${build.version} 5 | build.flexName=${build.artifactId}-flex-${build.version} 6 | build.as3Name=${build.artifactId}-only-${build.version} 7 | --------------------------------------------------------------------------------