Skip to content

Commit

Permalink
バリデーションを作成
Browse files Browse the repository at this point in the history
  • Loading branch information
tfandkusu committed Aug 12, 2024
1 parent 219d0d6 commit a80e2d5
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/main/kotlin/com/tfandkusu/ga913yaml/Validator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ object Validator {
checkEventNameLength(screens)
checkEventParameterKeyLength(screens)
checkEventCount(screens)
checkDuplicateEventName(screens)
}

/**
Expand Down Expand Up @@ -37,7 +38,7 @@ object Validator {
if (parameter.eventParameterKey.length > 40) {
throw IllegalArgumentException(
"画面内操作イベント " + screen.className + "." + action.className + " のパラメータキー " +
parameter.propertyName + " は40文字を超えています。",
parameter.propertyName + " は40文字を超えています。",
)
}
}
Expand All @@ -55,4 +56,20 @@ object Validator {
throw IllegalArgumentException("イベント種類数が500を超えています。")
}
}

private fun checkDuplicateEventName(screens: List<Screen>) {
val eventNames = mutableSetOf<String>()
for (screen in screens) {
if (!eventNames.add(screen.eventName)) {
throw IllegalArgumentException("画面遷移イベント " + screen.className + " は他のイベントと重複しています。")
}
for (action in screen.actions) {
if (!eventNames.add(screen.eventName + action.eventName)) {
throw IllegalArgumentException(
"画面内操作イベント " + screen.className + "." + action.className + " は他のイベントと重複しています。",
)
}
}
}
}
}
85 changes: 85 additions & 0 deletions src/test/kotlin/com/tfandkusu/ga913yaml/ValidatorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,89 @@ class ValidatorTest {
assertEquals("イベント種類数が500を超えています。", e.message)
}
}

@Test
fun checkScreenEventNameDuplicate() {
val screens =
listOf(
Screen(
description = "画面1",
className = "Screen1",
eventName = "Screen1",
),
Screen(
description = "画面2",
className = "Screen2",
eventName = "Screen1",
),
)
try {
Validator.validate(screens)
fail()
} catch (e: IllegalArgumentException) {
assertEquals("画面遷移イベント Screen2 は他のイベントと重複しています。", e.message)
}
}

@Test
fun checkActionEventNameDuplicate() {
val screens =
listOf(
Screen(
description = "画面1",
className = "Screen1",
eventName = "Screen1",
actions =
listOf(
Action(
description = "画面内操作1",
className = "Action1",
eventName = "Action1",
),
Action(
description = "画面内操作2",
className = "Action2",
eventName = "Action1",
),
),
),
)
try {
Validator.validate(screens)
fail()
} catch (e: IllegalArgumentException) {
assertEquals("画面内操作イベント Screen1.Action2 は他のイベントと重複しています。", e.message)
}
}

@Test
fun checkJoinedEventNameDuplicate() {
val screens =
listOf(
Screen(
description = "画面1",
className = "Screen1",
eventName = "Screen1",
actions =
listOf(
Action(
description = "画面内操作1",
className = "Action1",
eventName = "Action1",
),
),
),
Screen(
description = "画面2",
className = "Screen2",
eventName = "Screen1Action1",
),
)
try {
Validator.validate(screens)
fail()
} catch (e: IllegalArgumentException) {
assertEquals("画面遷移イベント Screen2 は他のイベントと重複しています。", e.message)
}
}
}

0 comments on commit a80e2d5

Please sign in to comment.