karate - 空手道比赛包含深度无法正常工作
问题描述
我们来自这里:https ://github.com/intuit/karate#match-contains-deep
正如它所说:
这会修改 match contains 的行为,以便为“深度包含”匹配处理嵌套列表或对象,...,您只想检查各种“树”数据中的某些值
所以让我们试着玩一下,找到一些{e: 5},它会在树的深处,当original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
Feature: Match contains deep
# match contains deep test (works ok, but this is not "deep" by any stretch of imagination, this is guiding the whole path in the search)
Scenario: match contains deep test modified original
* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
* def expected = { d: { e: 5 } }
* match original contains deep expected
#Thats was not deep, this is deep (fails, and this is what anyone would understand by "deep")
Scenario: match contains deep
* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
* def expected = { e: 5 }
* match original contains deep expected
#So you dont need deep (fails)
Scenario: match contains test modified original without deep
* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
* def expected = { d: { e: 5 } }
* match original contains expected
#So maybe it works with any (fails)
Scenario: match contains test modified original
* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
* def expected = { e: 5 }
* match original contains any expected
#Maybe I'm tripping with syntax (fails)
Scenario: match contains deep test my test #2
* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
* def expected = e: 5
* match original contains deep expected
#So maybe I'm tripping with syntax and semantics, and its any (fails)
Scenario: match contains deep test my test #2
* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
* def expected = e: 5
* match original contains any expected
所以,要么我没有真正得到这个东西,要么它不能像预期的那样工作,即我想检查放置在树中任何位置的现有键值对。
如果有人可以对此有所启发,那就太好了。正如我所看到的,@PeterThomas 正在回答大多数用空手道标记的问题,我要感谢他为将这个工具交到社区手中所做的巨大努力。
解决方案
@Greco,对不起,迟到了你是对的,最初我还认为 deep 能够在任何地方找到键值对,但遗憾的是它不是这样的。我理解这些术语的方式是:
contains - 在根对象中找到提到的键,但它们的值完全匹配。contains deep - 在根对象中找到提到的键,然后可以允许这些键对其值进行部分匹配,就像 contains 允许根对象进行部分匹配一样。
就像@Peter 说的那样,你必须形成一条路径,但它可以达到任何水平。
* def original = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: {f:5,g:6} } }
* def expected = { d: { e: {f:5} } }
* match original contains deep expected
推荐阅读
- excel - 如何避免运行时错误 -2147221080 (800401a8):自动化错误?VBA
- ruby-on-rails - 升级到 pg 1.2.x 后出现符号查找错误
- python - 标准 Anaconda 安装程序中是否有转换地球坐标系的功能?
- bash - 通过搜索从字符串中提取 2 个字段
- python - rllib 中的“num_envs_per_worker”有什么作用?
- java - 采用非嵌套 JSON 字符串并构建 Json 嵌套字符串
- javascript - 触发循环生成的多个弹出窗口
- python - 在列表理解中创建/导出数据帧到 csv
- javascript - 为什么在弹出窗口中调用此代码时无法正常工作
- xcode - 模拟 iPad Xcode 11/SwiftUI 时不需要的灰色区域