Skip to content

Commit 188e4a1

Browse files
authored
Merge pull request #1792 from madsboddum/item-name-test
Regression test for static items with object names containing non-ASC…
2 parents 51f6121 + 05252b1 commit 188e4a1

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/***********************************************************************************
2+
* Copyright (c) 2025 /// Project SWG /// www.projectswg.com *
3+
* *
4+
* ProjectSWG is an emulation project for Star Wars Galaxies founded on *
5+
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
6+
* Our goal is to create one or more emulators which will provide servers for *
7+
* players to continue playing a game similar to the one they used to play. *
8+
* *
9+
* This file is part of Holocore. *
10+
* *
11+
* --------------------------------------------------------------------------------*
12+
* *
13+
* Holocore is free software: you can redistribute it and/or modify *
14+
* it under the terms of the GNU Affero General Public License as *
15+
* published by the Free Software Foundation, either version 3 of the *
16+
* License, or (at your option) any later version. *
17+
* *
18+
* Holocore is distributed in the hope that it will be useful, *
19+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
20+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21+
* GNU Affero General Public License for more details. *
22+
* *
23+
* You should have received a copy of the GNU Affero General Public License *
24+
* along with Holocore. If not, see <http://www.gnu.org/licenses/>. *
25+
***********************************************************************************/
26+
package com.projectswg.holocore.resources.support.data.server_info.loader
27+
28+
import org.junit.jupiter.api.Assertions.assertTrue
29+
import org.junit.jupiter.api.Named
30+
import org.junit.jupiter.params.ParameterizedTest
31+
import org.junit.jupiter.params.provider.Arguments
32+
import org.junit.jupiter.params.provider.MethodSource
33+
import java.nio.charset.StandardCharsets
34+
35+
class StaticItemLoaderTest {
36+
37+
companion object {
38+
@JvmStatic
39+
private fun staticItemInfos(): Collection<Arguments> {
40+
return ServerData.staticItems.items.map { Arguments.of(Named.of(it.itemName, it)) }
41+
}
42+
}
43+
44+
private val encoder = StandardCharsets.US_ASCII.newEncoder()
45+
46+
@ParameterizedTest
47+
@MethodSource("staticItemInfos")
48+
fun `object name is valid ASCII`(staticItemInfo: StaticItemLoader.StaticItemInfo) {
49+
assertTrue(encoder.canEncode(staticItemInfo.stringName)) { generateInvalidAsciiErrorMessage(staticItemInfo) }
50+
}
51+
52+
private fun generateInvalidAsciiErrorMessage(staticItemInfo: StaticItemLoader.StaticItemInfo): String {
53+
val stringName = staticItemInfo.stringName
54+
55+
// Detect invalid ASCII characters and print them as an array.
56+
val invalidChars = stringName.toCharArray().filter { !encoder.canEncode(it) }
57+
58+
return "$stringName contains non-ASCII characters. These will not display correctly in the client. Please remove/replace these: $invalidChars"
59+
}
60+
}

0 commit comments

Comments
 (0)