From a80e2d58dd6ddd160b3c872b71941b8bd4fd842c Mon Sep 17 00:00:00 2001 From: Haruhiko Takada Date: Tue, 13 Aug 2024 00:06:00 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=90=E3=83=AA=E3=83=87=E3=83=BC=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tfandkusu/ga913yaml/Validator.kt | 19 ++++- .../com/tfandkusu/ga913yaml/ValidatorTest.kt | 85 +++++++++++++++++++ 2 files changed, 103 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/tfandkusu/ga913yaml/Validator.kt b/src/main/kotlin/com/tfandkusu/ga913yaml/Validator.kt index 0cc19a9..a49aefe 100644 --- a/src/main/kotlin/com/tfandkusu/ga913yaml/Validator.kt +++ b/src/main/kotlin/com/tfandkusu/ga913yaml/Validator.kt @@ -7,6 +7,7 @@ object Validator { checkEventNameLength(screens) checkEventParameterKeyLength(screens) checkEventCount(screens) + checkDuplicateEventName(screens) } /** @@ -37,7 +38,7 @@ object Validator { if (parameter.eventParameterKey.length > 40) { throw IllegalArgumentException( "画面内操作イベント " + screen.className + "." + action.className + " のパラメータキー " + - parameter.propertyName + " は40文字を超えています。", + parameter.propertyName + " は40文字を超えています。", ) } } @@ -55,4 +56,20 @@ object Validator { throw IllegalArgumentException("イベント種類数が500を超えています。") } } + + private fun checkDuplicateEventName(screens: List) { + val eventNames = mutableSetOf() + 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 + " は他のイベントと重複しています。", + ) + } + } + } + } } diff --git a/src/test/kotlin/com/tfandkusu/ga913yaml/ValidatorTest.kt b/src/test/kotlin/com/tfandkusu/ga913yaml/ValidatorTest.kt index 02c59aa..956d8f5 100644 --- a/src/test/kotlin/com/tfandkusu/ga913yaml/ValidatorTest.kt +++ b/src/test/kotlin/com/tfandkusu/ga913yaml/ValidatorTest.kt @@ -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) + } + } }