parent
118093e4e3
commit
7e1ac785cd
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2021 dorkbox, llc
|
||||
* Copyright 2023 dorkbox, llc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -30,7 +30,7 @@ class MetadataVersionTest {
|
|||
fun mustCompareEachIdentifierSeparately() {
|
||||
val v1 = MetadataVersion(arrayOf("beta", "2", "abc"))
|
||||
val v2 = MetadataVersion(arrayOf("beta", "1", "edf"))
|
||||
Assert.assertTrue(0 < v1.compareTo(v2))
|
||||
Assert.assertTrue(v1 > v2)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -51,21 +51,21 @@ class MetadataVersionTest {
|
|||
fun shouldComapareDigitsOnlyIdentifiersNumerically() {
|
||||
val v1 = MetadataVersion(arrayOf("alpha", "123"))
|
||||
val v2 = MetadataVersion(arrayOf("alpha", "321"))
|
||||
Assert.assertTrue(0 > v1.compareTo(v2))
|
||||
Assert.assertTrue(v1 < v2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldCompareIdentifiersCountIfCommonIdentifiersAreEqual() {
|
||||
val v1 = MetadataVersion(arrayOf("beta", "abc"))
|
||||
val v2 = MetadataVersion(arrayOf("beta", "abc", "def"))
|
||||
Assert.assertTrue(0 > v1.compareTo(v2))
|
||||
Assert.assertTrue(v1 < v2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldCompareMixedIdentifiersLexicallyInAsciiSortOrder() {
|
||||
val v1 = MetadataVersion(arrayOf("beta", "abc"))
|
||||
val v2 = MetadataVersion(arrayOf("beta", "111"))
|
||||
Assert.assertTrue(0 < v1.compareTo(v2))
|
||||
Assert.assertTrue(v1 > v2)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -73,8 +73,8 @@ class MetadataVersionTest {
|
|||
val v1 = MetadataVersion(arrayOf("alpha", "123"))
|
||||
val v2 = MetadataVersion(arrayOf("alpha", "123"))
|
||||
val v3 = MetadataVersion(arrayOf("alpha", "321"))
|
||||
Assert.assertTrue(v1.equals(v2))
|
||||
Assert.assertFalse(v1.equals(v3))
|
||||
Assert.assertTrue(v1 == v2)
|
||||
Assert.assertFalse(v1 == v3)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -88,7 +88,7 @@ class MetadataVersionTest {
|
|||
fun shouldReturnNegativeWhenComparedToNullMetadataVersion() {
|
||||
val v1 = MetadataVersion(arrayOf())
|
||||
val v2 = MetadataVersion.NULL
|
||||
Assert.assertTrue(0 > v1.compareTo(v2))
|
||||
Assert.assertTrue(v1 < v2)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,9 +98,9 @@ class MetadataVersionTest {
|
|||
val v1 = MetadataVersion.NULL
|
||||
val v2 = MetadataVersion.NULL
|
||||
val v3 = MetadataVersion(arrayOf())
|
||||
Assert.assertTrue(v1.equals(v2))
|
||||
Assert.assertTrue(v2.equals(v1))
|
||||
Assert.assertFalse(v1.equals(v3))
|
||||
Assert.assertTrue(v1 == v2)
|
||||
Assert.assertTrue(v2 == v1)
|
||||
Assert.assertFalse(v1 == v3)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -113,7 +113,7 @@ class MetadataVersionTest {
|
|||
fun shouldReturnPositiveWhenComparedToNonNullMetadataVersion() {
|
||||
val v1 = MetadataVersion.NULL
|
||||
val v2 = MetadataVersion(arrayOf())
|
||||
Assert.assertTrue(0 < v1.compareTo(v2))
|
||||
Assert.assertTrue(v1 > v2)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -145,23 +145,23 @@ class MetadataVersionTest {
|
|||
fun shouldBeConsistent() {
|
||||
val v1 = MetadataVersion(arrayOf("alpha", "123"))
|
||||
val v2 = MetadataVersion(arrayOf("alpha", "123"))
|
||||
Assert.assertTrue(v1.equals(v2))
|
||||
Assert.assertTrue(v1.equals(v2))
|
||||
Assert.assertTrue(v1.equals(v2))
|
||||
Assert.assertTrue(v1 == v2)
|
||||
Assert.assertTrue(v1 == v2)
|
||||
Assert.assertTrue(v1 == v2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldBeReflexive() {
|
||||
val v = MetadataVersion(arrayOf("alpha", "123"))
|
||||
Assert.assertTrue(v.equals(v))
|
||||
Assert.assertTrue(v == v)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldBeSymmetric() {
|
||||
val v1 = MetadataVersion(arrayOf("alpha", "123"))
|
||||
val v2 = MetadataVersion(arrayOf("alpha", "123"))
|
||||
Assert.assertTrue(v1.equals(v2))
|
||||
Assert.assertTrue(v2.equals(v1))
|
||||
Assert.assertTrue(v1 == v2)
|
||||
Assert.assertTrue(v2 == v1)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -169,16 +169,16 @@ class MetadataVersionTest {
|
|||
val v1 = MetadataVersion(arrayOf("alpha", "123"))
|
||||
val v2 = MetadataVersion(arrayOf("alpha", "123"))
|
||||
val v3 = MetadataVersion(arrayOf("alpha", "123"))
|
||||
Assert.assertTrue(v1.equals(v2))
|
||||
Assert.assertTrue(v2.equals(v3))
|
||||
Assert.assertTrue(v1.equals(v3))
|
||||
Assert.assertTrue(v1 == v2)
|
||||
Assert.assertTrue(v2 == v3)
|
||||
Assert.assertTrue(v1 == v3)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldReturnFalseIfOtherVersionIsNull() {
|
||||
val v1 = MetadataVersion(arrayOf("alpha", "123"))
|
||||
val v2: MetadataVersion? = null
|
||||
Assert.assertFalse(v1.equals(v2))
|
||||
Assert.assertFalse(v1 == v2)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -193,7 +193,7 @@ class MetadataVersionTest {
|
|||
fun shouldReturnSameHashCodeIfVersionsAreEqual() {
|
||||
val v1 = MetadataVersion(arrayOf("alpha", "123"))
|
||||
val v2 = MetadataVersion(arrayOf("alpha", "123"))
|
||||
Assert.assertTrue(v1.equals(v2))
|
||||
Assert.assertTrue(v1 == v2)
|
||||
Assert.assertEquals(v1.hashCode().toLong(), v2.hashCode().toLong())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2021 dorkbox, llc
|
||||
* Copyright 2023 dorkbox, llc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -34,7 +34,7 @@ class LexerTest {
|
|||
Lexer.Token(
|
||||
Lexer.Token.Type.NUMERIC, "3", 4
|
||||
),
|
||||
Lexer.Token(Lexer.Token.Type.EOI, null, 5)
|
||||
Lexer.Token(Lexer.Token.Type.EOI, "", 5)
|
||||
)
|
||||
val lexer = Lexer()
|
||||
val stream = lexer.tokenize("1.2.3")
|
||||
|
@ -56,7 +56,7 @@ class LexerTest {
|
|||
fun shouldSkipWhitespaces() {
|
||||
val expected = arrayOf(
|
||||
Lexer.Token(Lexer.Token.Type.GREATER, ">", 0), Lexer.Token(Lexer.Token.Type.NUMERIC, "1", 2), Lexer.Token(
|
||||
Lexer.Token.Type.EOI, null, 3
|
||||
Lexer.Token.Type.EOI, "", 3
|
||||
)
|
||||
)
|
||||
val lexer = Lexer()
|
||||
|
@ -77,7 +77,7 @@ class LexerTest {
|
|||
Lexer.Token.Type.DOT, ".", 4
|
||||
),
|
||||
Lexer.Token(Lexer.Token.Type.NUMERIC, "0", 5),
|
||||
Lexer.Token(Lexer.Token.Type.EOI, null, 6)
|
||||
Lexer.Token(Lexer.Token.Type.EOI, "", 6)
|
||||
)
|
||||
val lexer = Lexer()
|
||||
val stream = lexer.tokenize(">1.0.0")
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2021 dorkbox, llc
|
||||
* Copyright 2023 dorkbox, llc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -15,7 +15,10 @@
|
|||
*/
|
||||
package dorkbox.version.expr;
|
||||
|
||||
import static dorkbox.version.expr.Lexer.Token.Type.*;
|
||||
import static dorkbox.version.expr.Lexer.Token.Type.AND;
|
||||
import static dorkbox.version.expr.Lexer.Token.Type.EOI;
|
||||
import static dorkbox.version.expr.Lexer.Token.Type.NUMERIC;
|
||||
import static dorkbox.version.expr.Lexer.Token.Type.RIGHT_PAREN;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
@ -41,9 +44,9 @@ class ParserErrorHandlingTest {
|
|||
public static
|
||||
Collection<Object[]> parameters() {
|
||||
return Arrays.asList(new Object[][] {{"1)", new Token(RIGHT_PAREN, ")", 1), new Token.Type[] {EOI}},
|
||||
{"(>1.0.1", new Token(EOI, null, 7), new Token.Type[] {RIGHT_PAREN}},
|
||||
{"((>=1 & <2)", new Token(EOI, null, 11), new Token.Type[] {RIGHT_PAREN}},
|
||||
{">=1.0.0 &", new Token(EOI, null, 9), new Token.Type[] {NUMERIC}},
|
||||
{"(>1.0.1", new Token(EOI, "", 7), new Token.Type[] {RIGHT_PAREN}},
|
||||
{"((>=1 & <2)", new Token(EOI, "", 11), new Token.Type[] {RIGHT_PAREN}},
|
||||
{">=1.0.0 &", new Token(EOI, "", 9), new Token.Type[] {NUMERIC}},
|
||||
{"(>2.0 |)", new Token(RIGHT_PAREN, ")", 7), new Token.Type[] {NUMERIC}},
|
||||
{"& 1.2", new Token(AND, "&", 0), new Token.Type[] {NUMERIC}},});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue