mirror of
https://github.com/Aminark/legado-ios.git
synced 2026-10-24 12:51:22 +08:00
feat: open-source 小浣熊阅读 for iOS
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import Testing
|
||||
@testable import LegadoCore
|
||||
|
||||
struct RuleExpressionParserTests {
|
||||
private let parser = RuleExpressionParser()
|
||||
|
||||
@Test func detectsModesAndReplacement() throws {
|
||||
let plan = try parser.parse("@Json:$.book.name##\\s+## ")
|
||||
|
||||
#expect(plan.combination == .single)
|
||||
#expect(plan.branches.count == 1)
|
||||
#expect(plan.branches[0].mode == .jsonPath)
|
||||
#expect(plan.branches[0].expression == "$.book.name")
|
||||
#expect(plan.branches[0].replacePattern == "\\s+")
|
||||
#expect(plan.branches[0].replacement == " ")
|
||||
}
|
||||
|
||||
@Test func doesNotSplitOperatorsInsideJSONPathFilter() throws {
|
||||
let plan = try parser.parse("$.books[?(@.enabled && @.score > 1)]||$.fallback")
|
||||
|
||||
#expect(plan.combination == .fallback)
|
||||
#expect(plan.branches.count == 2)
|
||||
#expect(plan.branches[0].expression.contains("&&"))
|
||||
}
|
||||
|
||||
@Test func rejectsUnbalancedRules() {
|
||||
#expect(throws: RuleEngineError.self) {
|
||||
try parser.parse("$.books[0")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user