Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Css3ColorTest.kt « ical4android « bitfire « at « java « androidTest « src - github.com/bitfireAT/ical4android.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b89dad8c65afbf7e9f3978daa082fd14d50ef9f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/***************************************************************************************************
 * Copyright © All Contributors. See LICENSE and AUTHORS in the root directory for details.
 **************************************************************************************************/

package at.bitfire.ical4android

import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test

class Css3ColorTest {

    @Test
    fun testColorFromString() {
        // color name
        assertEquals(0xffffff00.toInt(), Css3Color.colorFromString("yellow"))

        // RGB value
        assertEquals(0xffffff00.toInt(), Css3Color.colorFromString("#ffff00"))

        // ARGB value
        assertEquals(0xffffff00.toInt(), Css3Color.colorFromString("#ffffff00"))

        // invalid value
        assertNull(Css3Color.colorFromString("DoesNotExist"))
    }

    @Test
    fun testFromString() {
        // lower case
        assertEquals(0xffffff00.toInt(), Css3Color.fromString("yellow")?.argb)

        // capitalized
        assertEquals(0xffffff00.toInt(), Css3Color.fromString("Yellow")?.argb)

        // not-existing color
        assertNull(Css3Color.fromString("DoesNotExist"))
    }

    @Test
    fun testNearestMatch() {
        // every color is its own nearest match
        Css3Color.values().forEach {
            assertEquals(it.argb, Css3Color.nearestMatch(it.argb).argb)
        }
    }

}