Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
TarCV committed Jul 17, 2024
1 parent ae54bed commit 5dddc95
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 29 deletions.
4 changes: 2 additions & 2 deletions droid-selector/src/test/kotlin/BySelectorProperties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class BySelectorProperties {
.let { arbitraries ->
when (arbitraries.size) {
1 -> arbitraries[0].map { listOf(it) }
2 -> Combinators.combine(arbitraries[0], arbitraries[1]).`as` { a, b -> listOf(a, b) }
2 -> Combinators.combine(arbitraries[0], arbitraries[1]).`as` { a, b -> listOf<Any?>(a, b) }
else -> TODO()
}
}
Expand Down Expand Up @@ -101,7 +101,7 @@ class BySelectorProperties {
.let { arbitraries ->
when (arbitraries.size) {
1 -> arbitraries[0].map { listOf(it) }
2 -> Combinators.combine(arbitraries[0], arbitraries[1]).`as` { a, b -> listOf(a, b) }
2 -> Combinators.combine(arbitraries[0], arbitraries[1]).`as` { a, b -> listOf<Any?>(a, b) }
else -> TODO()
}
}
Expand Down
2 changes: 1 addition & 1 deletion droid-selector/src/test/kotlin/UiSelectorProperties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class UiSelectorProperties {
.let { arbitraries ->
when(arbitraries.size) {
1 -> arbitraries[0].map { listOf(it) }
2 -> Combinators.combine(arbitraries[0], arbitraries[1]).`as` { a, b, -> listOf(a, b)}
2 -> Combinators.combine(arbitraries[0], arbitraries[1]).`as` { a, b -> listOf<Any?>(a, b)}
else -> TODO()
}
}
Expand Down
1 change: 1 addition & 0 deletions droid-stubs/src/main/kotlin/android/util/Log.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.github.tarcv.testingteam.surveyor.Logger

class Log {
companion object {
@Suppress("UNUSED_PARAMETER")
@JvmStatic
fun isLoggable(a: String, b: Int): Boolean = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ fun NSStringCompareOptions.insert(item: StringCompareOption) {
this.add(item)
}

class NSString private constructor(val utf16: StringUTF16View, unused: Nothing?): StringUTF16View by utf16 {
class NSString private constructor(val utf16: StringUTF16View, @Suppress("UNUSED_PARAMETER") unused: Nothing?)
: StringUTF16View by utf16 {
constructor(utf16: StringUTF16View): this(Collections.unmodifiableList(utf16), null)

private val asString: String by lazy {
Expand All @@ -49,8 +50,9 @@ class NSString private constructor(val utf16: StringUTF16View, unused: Nothing?)
.let { NSString(it) }
}

@Suppress("FunctionName")
fun CompareOptions(flags: UInt = 0u): NSStringCompareOptions {
return StringCompareOption.values()
return StringCompareOption.entries
.filter { (flags and it.ordinal.toUInt()) == it.ordinal.toUInt() }
.toMutableSet()
}
Expand Down Expand Up @@ -190,26 +192,29 @@ operator fun StringUTF16View.get(index: StringUTF16ViewIndex): UniChar = this[in

@JvmInline
value class StringUTF16ViewIndex(val index: Int): Comparable<StringUTF16ViewIndex> {
override fun compareTo(other: StringUTF16ViewIndex): Int = Integer.compare(index, other.index)
override fun compareTo(other: StringUTF16ViewIndex): Int = index.compareTo(other.index)
}

@Suppress("UnusedReceiverParameter")
val StringUTF16View.startIndex: StringUTF16ViewIndex
get() = StringUTF16ViewIndex(0)
val StringUTF16View.endIndex: StringUTF16ViewIndex
get() = StringUTF16ViewIndex(this.size - 1)

fun StringUTF16View.index(from: Int, distance: UInt) = this.index(from, distance.toInt())

@Suppress("UnusedReceiverParameter")
fun StringUTF16View.index(from: Int, distance: Int): StringUTF16ViewIndex {
return StringUTF16ViewIndex(from + distance)
}

@Suppress("UnusedReceiverParameter")
fun StringUTF16View.index(from: StringUTF16ViewIndex, distance: Int): StringUTF16ViewIndex {
return StringUTF16ViewIndex(from.index + distance)
}

fun StringUTF16ViewIndex.utf16Offset(unused: StringUTF16View): Int = this.index
fun StringUTF16ViewIndex.utf16Offset(unused: NSString): Int = this.index
fun StringUTF16ViewIndex.utf16Offset(@Suppress("UNUSED_PARAMETER") unused: StringUTF16View): Int = this.index
fun StringUTF16ViewIndex.utf16Offset(@Suppress("UNUSED_PARAMETER") unused: NSString): Int = this.index

fun NSString(format: String, vararg args: Any?): NSString {
val specifierRegex = Regex("(?<!%)%(.)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ enum class ComparisonResult {
const val NSLocalizedDescriptionKey = "NSLocalizedDescriptionKey"
class NSError(
type: String,
code: Int,
@Suppress("UNUSED_PARAMETER") code: Int,
info: Map<String, Any>
): Exception(type + System.lineSeparator() + info) {
val localizedDescription: String = info[NSLocalizedDescriptionKey]?.toString() ?: ""
Expand All @@ -275,8 +275,15 @@ class NSError(
info: Map<String, Any>
): this(type.toString(), code, info)
}
fun GSPropertyListMake(obj: NSString, a1: Nothing?, asXml: Boolean, asDescription: Boolean, indent: Int, out: InOut<NSString>) {
require(a1 == null)
fun GSPropertyListMake(
obj: NSString,
a1: Nothing?,
asXml: Boolean,
asDescription: Boolean,
@Suppress("UNUSED_PARAMETER") indent: Int,
out: InOut<NSString>
) {
@Suppress("SENSELESS_COMPARISON") require(a1 == null)
require(!asXml)
require(asDescription)
val result = if (obj.utf16.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ internal data class XCUIElementQuery(
}
}

open fun firstMatch(): XCUIElement = allElementsBoundByAccessibilityElement.first()
fun firstMatch(): XCUIElement = allElementsBoundByAccessibilityElement.first()

open fun descendantsMatchingType(type: XCUIElementType): XCUIElementQuery {
fun descendantsMatchingType(type: XCUIElementType): XCUIElementQuery {
return copy(filters = filters + object : Resolver {
override fun resolve(prevResults: List<XCUIElement>): List<XCUIElement> {
return prevResults
Expand All @@ -65,7 +65,7 @@ internal data class XCUIElementQuery(
})
}

open fun matchingPredicate(predicate: NSPredicate): XCUIElementQuery {
fun matchingPredicate(predicate: NSPredicate): XCUIElementQuery {
return copy(filters = filters + object : Resolver {
override fun resolve(prevResults: List<XCUIElement>): List<XCUIElement> {
return prevResults
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,16 @@ private fun assertTrue(actual: Boolean, message: NSString) =
assertTrue(actual, message.toString())

private fun <T> assertEquals(expected: T, actual: T, message: NSString) {
assertEquals(toNSStringIfNeeded(expected), toNSStringIfNeeded(actual), message.toString())
}

private fun <T> toNSStringIfNeeded(expected: T) = if (expected is String) {
expected.toNSString()
} else {
expected
assertEquals(expected, actual, message.toString())
}

@Suppress("JoinDeclarationAndAssignment")
class PredicateTest {
@Test
fun testKVC() {
assertEquals("A Title".toNSString(), (dict["title".toNSString()]), "com.github.tarcv.testingteam.surveyor.ipredicate.valueForKeyPath: with string".toNSString())
assertEquals("A Title".toNSString(), (dict.valueForKeyPath("title".toNSString())), "com.github.tarcv.testingteam.surveyor.ipredicate.valueForKeyPath: with string".toNSString())
assertEquals("John".toNSString(), (dict.valueForKeyPath("Record1.Name".toNSString())), "com.github.tarcv.testingteam.surveyor.ipredicate.valueForKeyPath: with string".toNSString())
assertEquals("A Title".toNSString(), (dict["title".toNSString()] as NSString), "com.github.tarcv.testingteam.surveyor.ipredicate.valueForKeyPath: with string".toNSString())
assertEquals("A Title".toNSString(), (dict.valueForKeyPath("title".toNSString()) as NSString), "com.github.tarcv.testingteam.surveyor.ipredicate.valueForKeyPath: with string".toNSString())
assertEquals("John".toNSString(), (dict.valueForKeyPath("Record1.Name".toNSString()) as NSString), "com.github.tarcv.testingteam.surveyor.ipredicate.valueForKeyPath: with string".toNSString())
assertEquals(30, dict.valueForKeyPath("Record2.Age".toNSString()) as Int, "com.github.tarcv.testingteam.surveyor.ipredicate.valueForKeyPath: with int".toNSString())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ class LocateAction: AnAction() {
val project = getEventProject(e)
val service = project?.getService(LocateToolHoldingService::class.java) ?: return
val locator = service.getCurrentLocator() ?: return
val locatorType = service.locatorType ?: return project.notify(
"Can't locate an element when no locator type is selected",
NotificationType.ERROR
)
val locatorType = service.locatorType

// TODO: Check if locatorType supports current UI snapshot type
val (editor, xmlFile: PsiFile) = FileEditorManager.getInstance(project).selectedEditors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class LocatorTypeComboBoxAction: ComboBoxAction(), DumbAware {
val service = project?.getService(LocateToolHoldingService::class.java)
?: return@run false
service.locatorType.let {
if (it != null && !ActionPlaces.isMainMenuOrActionSearch(e.place)) {
if (!ActionPlaces.isMainMenuOrActionSearch(e.place)) {
presentation.text = it.title
}
}
Expand Down

0 comments on commit 5dddc95

Please sign in to comment.