@@ -2,79 +2,81 @@ package i18n
2
2
3
3
import com.natpryce.hamkrest.*
4
4
import com.natpryce.hamkrest.assertion.assertThat
5
+ import dev.minutest.Tests
6
+ import dev.minutest.given
7
+ import dev.minutest.junit.JUnit5Minutests
8
+ import dev.minutest.rootContext
9
+ import dev.minutest.test
5
10
import kickstart.i18n.BundledMessages
6
11
import kickstart.i18n.loadBundle
7
12
import kotlin.test.Test
8
13
import java.util.*
9
14
10
- class BundledMessagesTest {
15
+ class BundledMessagesTest : JUnit5Minutests {
16
+ @Tests
17
+ fun tests () = rootContext<BundledMessages > {
18
+ given { BundledMessages .rootedAt(" test/i18n" ) }
11
19
12
- val bundles = BundledMessages .rootedAt(" test/i18n" )
20
+ test(" loads translations in specified locale" ) {
21
+ val translations = loadBundle(" defaults" , Locale .FRENCH )
13
22
14
- @Test
15
- fun `loads translations in specified locale` () {
16
- val translations = bundles.loadBundle(" defaults" , Locale .FRENCH )
23
+ assertThat(
24
+ " translated value" , translations.interpolate(" app.value" ),
25
+ equalTo(" valeur par défaut" )
26
+ )
27
+ }
17
28
18
- assertThat(
19
- " translated value" , translations.interpolate(" app.value" ),
20
- equalTo(" valeur par défaut" )
21
- )
22
- }
29
+ test(" composes view translations" ) {
30
+ val translations = loadBundle(" views" , " model/page" , Locale .ENGLISH )
23
31
24
- @Test
25
- fun `composes view translations` () {
26
- val translations = bundles.loadBundle(" views" , " model/page" , Locale .ENGLISH )
32
+ assertThat(
33
+ " page value" , translations.interpolate(" page.value" ),
34
+ equalTo(" page value" )
35
+ )
36
+ assertThat(
37
+ " model value" , translations.interpolate(" model.value" ),
38
+ equalTo(" model default value" )
39
+ )
40
+ assertThat(
41
+ " default value" , translations.interpolate(" views.value" ),
42
+ equalTo(" views default value" )
43
+ )
44
+ }
27
45
28
- assertThat(
29
- " page value" , translations.interpolate(" page.value" ),
30
- equalTo(" page value" )
31
- )
32
- assertThat(
33
- " model value" , translations.interpolate(" model.value" ),
34
- equalTo(" model default value" )
35
- )
36
- assertThat(
37
- " default value" , translations.interpolate(" views.value" ),
38
- equalTo(" views default value" )
39
- )
40
- }
46
+ test(" looks up translation keys, starting with most specific" ) {
47
+ fun lookupValueIn (bundleName : String ): String? {
48
+ val translations = loadBundle(" views" , bundleName, Locale .ENGLISH )
49
+ return translations.interpolate(" value" )
50
+ }
41
51
42
- @Test
43
- fun `looks up translation keys, starting with most specific` () {
44
- fun lookupValueIn (bundleName : String ): String? {
45
- val translations = bundles.loadBundle(" views" , bundleName, Locale .ENGLISH )
46
- return translations.interpolate(" value" )
52
+ assertThat(" page value" , lookupValueIn(" model/page" ), equalTo(" page value" ))
53
+ assertThat(
54
+ " model default value" ,
55
+ lookupValueIn(" model/other" ),
56
+ equalTo(" model default value" )
57
+ )
58
+ assertThat(" views default value" , lookupValueIn(" other" ), equalTo(" views default value" ))
47
59
}
48
60
49
- assertThat(" page value" , lookupValueIn(" model/page" ), equalTo(" page value" ))
50
- assertThat(
51
- " model default value" ,
52
- lookupValueIn(" model/other" ),
53
- equalTo(" model default value" )
54
- )
55
- assertThat(" views default value" , lookupValueIn(" other" ), equalTo(" views default value" ))
56
- }
61
+ test(" ignores missing bundles" ) {
62
+ val translations = loadBundle(" missing" , Locale .ENGLISH )
57
63
58
- @Test
59
- fun `ignores missing bundles` () {
60
- val translations = bundles.loadBundle(" missing" , Locale .ENGLISH )
61
-
62
- assertThat(translations.interpolate(" key" ), absent())
63
- }
64
+ assertThat(translations.interpolate(" key" ), absent())
65
+ }
64
66
65
- @Test
66
- fun `provides search locations` () {
67
- val translations = bundles.loadBundle(" views" , " model/page" , Locale .ENGLISH )
67
+ test(" provides search locations" ) {
68
+ val translations = loadBundle(" views" , " model/page" , Locale .ENGLISH )
68
69
69
- val locations = translations.searchPath(" views.value" )
70
- .map { it.description }
70
+ val locations = translations.searchPath(" views.value" )
71
+ .map { it.description }
71
72
72
- assertThat(
73
- locations,
74
- allOf(
75
- hasElement(" bundle test/i18n/views/model/page in en" ),
76
- hasElement(" bundle test/i18n/views/model/defaults in en" ),
77
- hasElement(" bundle test/i18n/views/defaults in en" ))
78
- )
73
+ assertThat(
74
+ locations,
75
+ allOf(
76
+ hasElement(" bundle test/i18n/views/model/page in en" ),
77
+ hasElement(" bundle test/i18n/views/model/defaults in en" ),
78
+ hasElement(" bundle test/i18n/views/defaults in en" ))
79
+ )
80
+ }
79
81
}
80
82
}
0 commit comments