sv
来源:互联网 发布:淘宝上的血滴子是什么 编辑:程序博客网 时间:2024/05/13 03:49
package org.json4s import org.specs2.mutable.Specification import text.Document object NativeJsonQueryExamples extendsJsonQueryExamples[Document]("Native")with native.JsonMethods object JacksonJsonQueryExamples extendsJsonQueryExamples[JValue]("Jackson")with jackson.JsonMethods /** * System under specification for JSON Query Examples. */ abstract class JsonQueryExamples[T](mod:String) extends Specificationwith JsonMethods[T] { (mod+" JSON Query Examples") should { "List of IPs" in { val ips = for { JString(ip)<- json \\"ip" }yield ip ips must_== List("192.168.1.125","192.168.1.126","192.168.1.127","192.168.2.125","192.168.2.126") } "List of IPs converted to XML" in { val ips = <ips>{for { JString(ip) <- json \\"ip" }yield <ip>{ ip }</ip> }</ips> ips must_== <ips><ip>192.168.1.125</ip><ip>192.168.1.126</ip><ip>192.168.1.127</ip><ip>192.168.2.125</ip><ip>192.168.2.126</ip></ips> } "List of IPs in cluster2" in { val ips = for { cluster @ JObject(x) <- json \"data_center" if (x contains JField("name",JString("cluster2"))) JString(ip) <- cluster \\ "ip" }yield ip ips must_== List("192.168.2.125","192.168.2.126") } "Total cpus in data center" in { (for { JInt(x) <- json \\"cpus" }yield x) reduceLeft (_ + _) must_== 40 } "Servers sorted by uptime" in { case class Server(ip:String, uptime: Long) val servers = for { JArray(servers) <- json \\ "servers" JObject(server) <- servers JField("ip",JString(ip)) <- server JField("uptime",JInt(uptime)) <- server } yield Server(ip, uptime.longValue) servers sortWith (_.uptime > _.uptime) must_==List(Server("192.168.1.127",901214), Server("192.168.2.125",453423), Server("192.168.2.126",214312), Server("192.168.1.126",189822), Server("192.168.1.125",150123)) } "Clusters administered by liza" in { val clusters = for { JObject(cluster) <- json JField("admins",JArray(admins)) <- cluster if admins contains JString("liza") JField("name",JString(name)) <- cluster } yield name clusters must_== List("cluster2") } } lazy val json = parse(""" { "data_center": [ { "name": "cluster1", "servers": [ {"ip": "192.168.1.125", "uptime": 150123, "specs": {"cpus": 8, "ram": 2048}}, {"ip": "192.168.1.126", "uptime": 189822, "specs": {"cpus": 16, "ram": 4096}}, {"ip": "192.168.1.127", "uptime": 901214, "specs": {"cpus": 8, "ram": 4096}} ], "links": [ {"href": "http://www.example.com/admin", "name": "admin"}, {"href": "http://www,example.com/home", "name": "home"} ], "admins": ["jim12", "joe", "maddog"] }, { "name": "cluster2", "servers": [ {"ip": "192.168.2.125", "uptime": 453423, "specs": {"cpus": 4, "ram": 2048}}, {"ip": "192.168.2.126", "uptime": 214312, "specs": {"cpus": 4, "ram": 2048}} ], "links": [ {"href": "http://www.example2.com/admin", "name": "admin"}, {"href": "http://www,example2.com/home", "name": "home"} ], "admins": ["joe", "liza"] } ]}
0 0
- sv
- sv
- SV list
- SV function
- U9 如何配置SV
- 如何debug SV testbech
- 相等,全等.... in SV
- sv中$bitstorealshort() 函数
- SV 面向对象OOP
- SV语法个人小结
- SV中的interface
- SV之OOP基础知识
- SV 语法自测程序
- define在sv中的应用
- SV中Clock的处理
- [临时]sv:interface个人理解
- ln -sv tclsh8.4 /tools/bin/tclsh
- VCS自动连接NOVAS文件(SV enhance)
- 响应式资料收集
- 一起学CC3200之CRC校验
- [4] 对比原则
- 一道数据结构题
- Genymotion启动失败解决
- sv
- Windows7安装PADS2007详细步骤____亲自实验总结
- Wrapper class package.jaxws.methodName is not found. Have you run APT to generate them?解决方案
- 步伐
- Qt5.6+MinGW4.9.2+OpenCV3.1+Win10开发环境搭建
- [leetcode 75] Sort Colors-----------只有三种颜色的排序
- ssh: connect to host localhost port 22: Connection refused
- 源码解析ListView中的RecycleBin机制
- hdu 1677 Nested Dolls