From b27889c174a0b5c09445bb92e3b9fdb28ed2e66a Mon Sep 17 00:00:00 2001 From: DimaVilda Date: Sun, 15 Dec 2024 16:04:31 +0100 Subject: [PATCH 1/2] NOTASK - fix path normalization for Windows OS, add unit tests --- .../com/squareup/wire/schema/Location.kt | 4 +++- .../com/squareup/wire/schema/LocationTest.kt | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 wire-schema/src/commonTest/kotlin/com/squareup/wire/schema/LocationTest.kt diff --git a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Location.kt b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Location.kt index ab04e34e71..32b9890998 100644 --- a/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Location.kt +++ b/wire-schema/src/commonMain/kotlin/com/squareup/wire/schema/Location.kt @@ -70,7 +70,9 @@ data class Location( base: String, path: String, ): Location { - return Location(base.trimEnd('/'), path, -1, -1) + val normalizedBase = base.replace('\\', '/') + val normalizedPath = path.replace('\\', '/') + return Location(normalizedBase.trimEnd('/'), normalizedPath, -1, -1) } } } diff --git a/wire-schema/src/commonTest/kotlin/com/squareup/wire/schema/LocationTest.kt b/wire-schema/src/commonTest/kotlin/com/squareup/wire/schema/LocationTest.kt new file mode 100644 index 0000000000..6871f46fc0 --- /dev/null +++ b/wire-schema/src/commonTest/kotlin/com/squareup/wire/schema/LocationTest.kt @@ -0,0 +1,23 @@ +package com.squareup.wire.schema + +import kotlin.test.Test +import assertk.assertThat +import assertk.assertions.isEqualTo + +class LocationTest { + + @Test fun getWithBaseAndRelativePath() { + val location = Location.get("/base/dir", "test/file.proto") + assertThat(location.base).isEqualTo("/base/dir") + assertThat(location.path).isEqualTo("test/file.proto") + } + + @Test fun getWithWindowsStylePaths() { + val location = Location.get( + "C:\\Users\\protoDir", + "languageDir\\language.proto" + ) + assertThat(location.base).isEqualTo("C:/Users/protoDir") + assertThat(location.path).isEqualTo("languageDir/language.proto") + } +} From 410bdee9761da8901b294375af96ae37e962139f Mon Sep 17 00:00:00 2001 From: DimaVilda Date: Sun, 15 Dec 2024 18:17:47 +0100 Subject: [PATCH 2/2] NOTASK - apply spotless on a new file --- .../com/squareup/wire/schema/LocationTest.kt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/wire-schema/src/commonTest/kotlin/com/squareup/wire/schema/LocationTest.kt b/wire-schema/src/commonTest/kotlin/com/squareup/wire/schema/LocationTest.kt index 6871f46fc0..a7cb1d6a45 100644 --- a/wire-schema/src/commonTest/kotlin/com/squareup/wire/schema/LocationTest.kt +++ b/wire-schema/src/commonTest/kotlin/com/squareup/wire/schema/LocationTest.kt @@ -1,8 +1,23 @@ +/* + * Copyright (C) 2024 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.squareup.wire.schema -import kotlin.test.Test import assertk.assertThat import assertk.assertions.isEqualTo +import kotlin.test.Test class LocationTest { @@ -15,7 +30,7 @@ class LocationTest { @Test fun getWithWindowsStylePaths() { val location = Location.get( "C:\\Users\\protoDir", - "languageDir\\language.proto" + "languageDir\\language.proto", ) assertThat(location.base).isEqualTo("C:/Users/protoDir") assertThat(location.path).isEqualTo("languageDir/language.proto")