diff --git a/src/main/java/com/github/zafarkhaja/semver/expr/And.java b/src/main/java/com/github/zafarkhaja/semver/expr/And.java new file mode 100644 index 0000000..850d5d2 --- /dev/null +++ b/src/main/java/com/github/zafarkhaja/semver/expr/And.java @@ -0,0 +1,46 @@ +/* + * The MIT License + * + * Copyright 2013 Zafar Khaja . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.github.zafarkhaja.semver.expr; + +import com.github.zafarkhaja.semver.Version; + +/** + * + * @author Zafar Khaja + */ +class And implements Expression { + + private final Expression left; + private final Expression right; + + And(Expression left, Expression right) { + this.left = left; + this.right = right; + } + + @Override + public boolean interpret(Version version) { + return left.interpret(version) && right.interpret(version); + } +} diff --git a/src/main/java/com/github/zafarkhaja/semver/expr/Equal.java b/src/main/java/com/github/zafarkhaja/semver/expr/Equal.java new file mode 100644 index 0000000..71cb5f7 --- /dev/null +++ b/src/main/java/com/github/zafarkhaja/semver/expr/Equal.java @@ -0,0 +1,44 @@ +/* + * The MIT License + * + * Copyright 2013 Zafar Khaja . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.github.zafarkhaja.semver.expr; + +import com.github.zafarkhaja.semver.Version; + +/** + * + * @author Zafar Khaja + */ +class Equal implements Expression { + + private final Version parsedVersion; + + Equal(Version parsedVersion) { + this.parsedVersion = parsedVersion; + } + + @Override + public boolean interpret(Version version) { + return version.equals(parsedVersion); + } +} diff --git a/src/main/java/com/github/zafarkhaja/semver/expr/Expression.java b/src/main/java/com/github/zafarkhaja/semver/expr/Expression.java new file mode 100644 index 0000000..48ba122 --- /dev/null +++ b/src/main/java/com/github/zafarkhaja/semver/expr/Expression.java @@ -0,0 +1,34 @@ +/* + * The MIT License + * + * Copyright 2013 Zafar Khaja . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.github.zafarkhaja.semver.expr; + +import com.github.zafarkhaja.semver.Version; + +/** + * + * @author Zafar Khaja + */ +public interface Expression { + boolean interpret(Version version); +} diff --git a/src/main/java/com/github/zafarkhaja/semver/expr/Greater.java b/src/main/java/com/github/zafarkhaja/semver/expr/Greater.java new file mode 100644 index 0000000..21dc478 --- /dev/null +++ b/src/main/java/com/github/zafarkhaja/semver/expr/Greater.java @@ -0,0 +1,44 @@ +/* + * The MIT License + * + * Copyright 2013 Zafar Khaja . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.github.zafarkhaja.semver.expr; + +import com.github.zafarkhaja.semver.Version; + +/** + * + * @author Zafar Khaja + */ +class Greater implements Expression { + + private final Version parsedVersion; + + Greater(Version parsedVersion) { + this.parsedVersion = parsedVersion; + } + + @Override + public boolean interpret(Version version) { + return version.greaterThan(parsedVersion); + } +} diff --git a/src/main/java/com/github/zafarkhaja/semver/expr/GreaterOrEqual.java b/src/main/java/com/github/zafarkhaja/semver/expr/GreaterOrEqual.java new file mode 100644 index 0000000..a205ccd --- /dev/null +++ b/src/main/java/com/github/zafarkhaja/semver/expr/GreaterOrEqual.java @@ -0,0 +1,44 @@ +/* + * The MIT License + * + * Copyright 2013 Zafar Khaja . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.github.zafarkhaja.semver.expr; + +import com.github.zafarkhaja.semver.Version; + +/** + * + * @author Zafar Khaja + */ +class GreaterOrEqual implements Expression { + + private final Version parsedVersion; + + GreaterOrEqual(Version parsedVersion) { + this.parsedVersion = parsedVersion; + } + + @Override + public boolean interpret(Version version) { + return version.greaterThanOrEqualTo(parsedVersion); + } +} diff --git a/src/main/java/com/github/zafarkhaja/semver/expr/Less.java b/src/main/java/com/github/zafarkhaja/semver/expr/Less.java new file mode 100644 index 0000000..dd62450 --- /dev/null +++ b/src/main/java/com/github/zafarkhaja/semver/expr/Less.java @@ -0,0 +1,44 @@ +/* + * The MIT License + * + * Copyright 2013 Zafar Khaja . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.github.zafarkhaja.semver.expr; + +import com.github.zafarkhaja.semver.Version; + +/** + * + * @author Zafar Khaja + */ +class Less implements Expression { + + private final Version parsedVersion; + + Less(Version parsedVersion) { + this.parsedVersion = parsedVersion; + } + + @Override + public boolean interpret(Version version) { + return version.lessThan(parsedVersion); + } +} diff --git a/src/main/java/com/github/zafarkhaja/semver/expr/LessOrEqual.java b/src/main/java/com/github/zafarkhaja/semver/expr/LessOrEqual.java new file mode 100644 index 0000000..b6fd00a --- /dev/null +++ b/src/main/java/com/github/zafarkhaja/semver/expr/LessOrEqual.java @@ -0,0 +1,44 @@ +/* + * The MIT License + * + * Copyright 2013 Zafar Khaja . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.github.zafarkhaja.semver.expr; + +import com.github.zafarkhaja.semver.Version; + +/** + * + * @author Zafar Khaja + */ +class LessOrEqual implements Expression { + + private final Version parsedVersion; + + LessOrEqual(Version parsedVersion) { + this.parsedVersion = parsedVersion; + } + + @Override + public boolean interpret(Version version) { + return version.lessThanOrEqualTo(parsedVersion); + } +} diff --git a/src/main/java/com/github/zafarkhaja/semver/expr/Not.java b/src/main/java/com/github/zafarkhaja/semver/expr/Not.java new file mode 100644 index 0000000..a84d800 --- /dev/null +++ b/src/main/java/com/github/zafarkhaja/semver/expr/Not.java @@ -0,0 +1,44 @@ +/* + * The MIT License + * + * Copyright 2013 Zafar Khaja . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.github.zafarkhaja.semver.expr; + +import com.github.zafarkhaja.semver.Version; + +/** + * + * @author Zafar Khaja + */ +class Not implements Expression { + + private final Expression expr; + + Not(Expression expr) { + this.expr = expr; + } + + @Override + public boolean interpret(Version version) { + return !expr.interpret(version); + } +} diff --git a/src/main/java/com/github/zafarkhaja/semver/expr/NotEqual.java b/src/main/java/com/github/zafarkhaja/semver/expr/NotEqual.java new file mode 100644 index 0000000..60e8289 --- /dev/null +++ b/src/main/java/com/github/zafarkhaja/semver/expr/NotEqual.java @@ -0,0 +1,44 @@ +/* + * The MIT License + * + * Copyright 2013 Zafar Khaja . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.github.zafarkhaja.semver.expr; + +import com.github.zafarkhaja.semver.Version; + +/** + * + * @author Zafar Khaja + */ +class NotEqual implements Expression { + + private final Version parsedVersion; + + NotEqual(Version parsedVersion) { + this.parsedVersion = parsedVersion; + } + + @Override + public boolean interpret(Version version) { + return !version.equals(parsedVersion); + } +} diff --git a/src/main/java/com/github/zafarkhaja/semver/expr/Or.java b/src/main/java/com/github/zafarkhaja/semver/expr/Or.java new file mode 100644 index 0000000..dec3987 --- /dev/null +++ b/src/main/java/com/github/zafarkhaja/semver/expr/Or.java @@ -0,0 +1,46 @@ +/* + * The MIT License + * + * Copyright 2013 Zafar Khaja . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.github.zafarkhaja.semver.expr; + +import com.github.zafarkhaja.semver.Version; + +/** + * + * @author Zafar Khaja + */ +class Or implements Expression { + + private final Expression left; + private final Expression right; + + Or(Expression left, Expression right) { + this.left = left; + this.right = right; + } + + @Override + public boolean interpret(Version version) { + return left.interpret(version) || right.interpret(version); + } +} diff --git a/src/test/java/com/github/zafarkhaja/semver/expr/AndTest.java b/src/test/java/com/github/zafarkhaja/semver/expr/AndTest.java new file mode 100644 index 0000000..8c00ada --- /dev/null +++ b/src/test/java/com/github/zafarkhaja/semver/expr/AndTest.java @@ -0,0 +1,53 @@ +/* + * The MIT License + * + * Copyright 2013 Zafar Khaja . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.github.zafarkhaja.semver.expr; + +import com.github.zafarkhaja.semver.Version; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author Zafar Khaja + */ +public class AndTest { + + @Test + public void shouldCheckIfBothExpressionsEvaluateToTrue() { + Expression left = new Expression() { + @Override + public boolean interpret(Version version) { + return true; + } + }; + Expression right = new Expression() { + @Override + public boolean interpret(Version version) { + return true; + } + }; + And and = new And(left, right); + assertTrue(and.interpret(null)); + } +} diff --git a/src/test/java/com/github/zafarkhaja/semver/expr/EqualTest.java b/src/test/java/com/github/zafarkhaja/semver/expr/EqualTest.java new file mode 100644 index 0000000..e895b16 --- /dev/null +++ b/src/test/java/com/github/zafarkhaja/semver/expr/EqualTest.java @@ -0,0 +1,43 @@ +/* + * The MIT License + * + * Copyright 2013 Zafar Khaja . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.github.zafarkhaja.semver.expr; + +import com.github.zafarkhaja.semver.Version; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author Zafar Khaja + */ +public class EqualTest { + + @Test + public void shouldCheckIfVersionIsEqualToParsedVersion() { + Version parsed = Version.valueOf("1.2.3"); + Equal eq = new Equal(parsed); + assertTrue(eq.interpret(Version.valueOf("1.2.3"))); + assertFalse(eq.interpret(Version.valueOf("3.2.1"))); + } +} diff --git a/src/test/java/com/github/zafarkhaja/semver/expr/GreaterOrEqualTest.java b/src/test/java/com/github/zafarkhaja/semver/expr/GreaterOrEqualTest.java new file mode 100644 index 0000000..daa6110 --- /dev/null +++ b/src/test/java/com/github/zafarkhaja/semver/expr/GreaterOrEqualTest.java @@ -0,0 +1,44 @@ +/* + * The MIT License + * + * Copyright 2013 Zafar Khaja . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.github.zafarkhaja.semver.expr; + +import com.github.zafarkhaja.semver.Version; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author Zafar Khaja + */ +public class GreaterOrEqualTest { + + @Test + public void shouldCheckIfVersionIsGreaterThanOrEqualToParsedVersion() { + Version parsed = Version.valueOf("2.0.0"); + GreaterOrEqual ge = new GreaterOrEqual(parsed); + assertTrue(ge.interpret(Version.valueOf("3.2.1"))); + assertTrue(ge.interpret(Version.valueOf("2.0.0"))); + assertFalse(ge.interpret(Version.valueOf("1.2.3"))); + } +} diff --git a/src/test/java/com/github/zafarkhaja/semver/expr/GreaterTest.java b/src/test/java/com/github/zafarkhaja/semver/expr/GreaterTest.java new file mode 100644 index 0000000..26f6a15 --- /dev/null +++ b/src/test/java/com/github/zafarkhaja/semver/expr/GreaterTest.java @@ -0,0 +1,43 @@ +/* + * The MIT License + * + * Copyright 2013 Zafar Khaja . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.github.zafarkhaja.semver.expr; + +import com.github.zafarkhaja.semver.Version; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author Zafar Khaja + */ +public class GreaterTest { + + @Test + public void shouldCheckIfVersionIsGreaterThanParsedVersion() { + Version parsed = Version.valueOf("2.0.0"); + Greater gt = new Greater(parsed); + assertTrue(gt.interpret(Version.valueOf("3.2.1"))); + assertFalse(gt.interpret(Version.valueOf("1.2.3"))); + } +} diff --git a/src/test/java/com/github/zafarkhaja/semver/expr/LessOrEqualTest.java b/src/test/java/com/github/zafarkhaja/semver/expr/LessOrEqualTest.java new file mode 100644 index 0000000..c29d8e0 --- /dev/null +++ b/src/test/java/com/github/zafarkhaja/semver/expr/LessOrEqualTest.java @@ -0,0 +1,44 @@ +/* + * The MIT License + * + * Copyright 2013 Zafar Khaja . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.github.zafarkhaja.semver.expr; + +import com.github.zafarkhaja.semver.Version; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author Zafar Khaja + */ +public class LessOrEqualTest { + + @Test + public void shouldCheckIfVersionIsLessThanOrEqualToParsedVersion() { + Version parsed = Version.valueOf("2.0.0"); + LessOrEqual le = new LessOrEqual(parsed); + assertTrue(le.interpret(Version.valueOf("1.2.3"))); + assertTrue(le.interpret(Version.valueOf("2.0.0"))); + assertFalse(le.interpret(Version.valueOf("3.2.1"))); + } +} diff --git a/src/test/java/com/github/zafarkhaja/semver/expr/LessTest.java b/src/test/java/com/github/zafarkhaja/semver/expr/LessTest.java new file mode 100644 index 0000000..29b304c --- /dev/null +++ b/src/test/java/com/github/zafarkhaja/semver/expr/LessTest.java @@ -0,0 +1,43 @@ +/* + * The MIT License + * + * Copyright 2013 Zafar Khaja . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.github.zafarkhaja.semver.expr; + +import com.github.zafarkhaja.semver.Version; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author Zafar Khaja + */ +public class LessTest { + + @Test + public void shouldCheckIfVersionIsLessThanParsedVersion() { + Version parsed = Version.valueOf("2.0.0"); + Less lt = new Less(parsed); + assertTrue(lt.interpret(Version.valueOf("1.2.3"))); + assertFalse(lt.interpret(Version.valueOf("3.2.1"))); + } +} diff --git a/src/test/java/com/github/zafarkhaja/semver/expr/NotEqualTest.java b/src/test/java/com/github/zafarkhaja/semver/expr/NotEqualTest.java new file mode 100644 index 0000000..b02f9dd --- /dev/null +++ b/src/test/java/com/github/zafarkhaja/semver/expr/NotEqualTest.java @@ -0,0 +1,43 @@ +/* + * The MIT License + * + * Copyright 2013 Zafar Khaja . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.github.zafarkhaja.semver.expr; + +import com.github.zafarkhaja.semver.Version; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author Zafar Khaja + */ +public class NotEqualTest { + + @Test + public void shouldCheckIfVersionIsNotEqualToParsedVersion() { + Version parsed = Version.valueOf("1.2.3"); + NotEqual ne = new NotEqual(parsed); + assertTrue(ne.interpret(Version.valueOf("3.2.1"))); + assertFalse(ne.interpret(Version.valueOf("1.2.3"))); + } +} diff --git a/src/test/java/com/github/zafarkhaja/semver/expr/NotTest.java b/src/test/java/com/github/zafarkhaja/semver/expr/NotTest.java new file mode 100644 index 0000000..f4bc0e3 --- /dev/null +++ b/src/test/java/com/github/zafarkhaja/semver/expr/NotTest.java @@ -0,0 +1,56 @@ +/* + * The MIT License + * + * Copyright 2013 Zafar Khaja . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.github.zafarkhaja.semver.expr; + +import com.github.zafarkhaja.semver.Version; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author Zafar Khaja + */ +public class NotTest { + + @Test + public void shouldRevertBooleanResultOfExpression() { + Expression expr1 = new Expression() { + @Override + public boolean interpret(Version version) { + return false; + } + }; + Expression expr2 = new Expression() { + @Override + public boolean interpret(Version version) { + return true; + } + }; + Not not; + not = new Not(expr1); + assertTrue(not.interpret(null)); + not = new Not(expr2); + assertFalse(not.interpret(null)); + } +} diff --git a/src/test/java/com/github/zafarkhaja/semver/expr/OrTest.java b/src/test/java/com/github/zafarkhaja/semver/expr/OrTest.java new file mode 100644 index 0000000..154ad94 --- /dev/null +++ b/src/test/java/com/github/zafarkhaja/semver/expr/OrTest.java @@ -0,0 +1,53 @@ +/* + * The MIT License + * + * Copyright 2013 Zafar Khaja . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.github.zafarkhaja.semver.expr; + +import com.github.zafarkhaja.semver.Version; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author Zafar Khaja + */ +public class OrTest { + + @Test + public void shouldCheckIfOneOfTwoExpressionsEvaluateToTrue() { + Expression left = new Expression() { + @Override + public boolean interpret(Version version) { + return false; + } + }; + Expression right = new Expression() { + @Override + public boolean interpret(Version version) { + return true; + } + }; + Or or = new Or(left, right); + assertTrue(or.interpret(null)); + } +}