当前位置: 首页>>代码示例>>Scala>>正文


Scala Assert类代码示例

本文整理汇总了Scala中io.scalajs.nodejs.Assert的典型用法代码示例。如果您正苦于以下问题:Scala Assert类的具体用法?Scala Assert怎么用?Scala Assert使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Assert类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: CheerioTest

//设置package包名称以及导入依赖的类
package io.scalajs.npm.cheerio

import io.scalajs.JSON
import io.scalajs.nodejs.Assert
import org.scalatest.FunSpec


class CheerioTest extends FunSpec {

  describe("Cheerio") {

    it("supports manipulating HTML") {
      val input = """<h2 class="title">Hello world</h2>"""
      val $ = Cheerio.load(input)

      $("h2.title").text("Hello there!")
      $("h2").addClass("welcome")

      val output = $.html()
      info(s"before: $input")
      info(s"after:  $output")
      Assert.equal(output, """<h2 class="title welcome">Hello there!</h2>""")
    }

    it("supports text extraction") {
      val $ = Cheerio.load("""<ul><li class="orange">Hello world</li></ul>""")
      val text = $("li[class=orange]").html()
      info(s"text: $text")
      Assert.equal(text, "Hello world")
    }

    it("supports reading component state") {
      val $ = Cheerio.load("""<input name="agree" type="checkbox">""")
      val value = $("input[type='checkbox']").prop("checked")
      info(s"isChecked: $value")
      Assert.equal(value, false)
    }

    it("supports updating component state") {
      val $ = Cheerio.load("""<input name="agree" type="checkbox">""")
      val value = $("input[type='checkbox']").prop("checked", true).`val`()
      info(s"setChecked: $value")
      Assert.equal(value, "on")
    }

    it("supports serialization") {
      val $ = Cheerio.load("""<input name="agree" type="checkbox">""")
      val value = $("""<form><input name="foo" value="bar" /></form>""").serializeArray()
      info(s"value: ${JSON.stringify(value)}")
      Assert(value, """[{"name":"foo","value":"bar"}]""")
    }

    it("supports $.root()") {
      val $ = Cheerio.load("""<input name="agree" type="checkbox">""")
      val value = $.root().append("""<ul id="vegetables"></ul>""").html()
      info(s"value: $value")
    }

  }

} 
开发者ID:scalajs-io,项目名称:cheerio,代码行数:62,代码来源:CheerioTest.scala

示例2: BufferMakerTest

//设置package包名称以及导入依赖的类
package io.scalajs.npm.buffermaker

import io.scalajs.nodejs.Assert
import io.scalajs.npm.bignum.BigNum
import org.scalatest._


class BufferMakerTest extends FunSpec {

  describe("BufferMaker") {

    it("supports binary strings 1") {
      val someBuffer = new BufferMaker()
        .UInt8(1)
        .UInt16BE(2)
        .UInt32BE(3)
        .Int64BE(new BigNum("4")) // uses the BigNum library
        .string("this is a test!")
        .make()

      info(someBuffer.toString())
      Assert(someBuffer.toString(),
             "<Buffer 01 00 02 00 00 00 03 00 00 00 00 00 00 00 04 74 68 69 73 20 69 73 20 61 20 74 65 73 74 21>")
    }

    it("supports binary strings 2") {
      val someBuffer = new BufferMaker()
        .Int8(1)
        .Int16BE(2)
        .Int32BE(3)
        .Int64BE(4)
        .make()

      info(someBuffer.toString())
      Assert(someBuffer.toString(), "<Buffer 01 00 02 00 00 00 03 00 00 00 00 00 00 00 04>")
    }

    it("supports mixed endian binary strings") {
      val someBuffer = new BufferMaker()
        .UInt16LE(1)
        .UInt32LE(2)
        .Int16LE(3)
        .Int32LE(4)
        .FloatLE(5)
        .FloatBE(6)
        .DoubleLE(7)
        .DoubleBE(8)
        .make()

      info(someBuffer.toString())
      Assert(
        someBuffer.toString(),
        "<Buffer 01 00 02 00 00 00 03 00 04 00 00 00 00 00 a0 40 40 c0 00 00 00 00 00 00 00 00 1c 40 40 20 00 00 00 00 00 00>")
    }

  }

} 
开发者ID:scalajs-io,项目名称:buffermaker,代码行数:59,代码来源:BufferMakerTest.scala

示例3: BigNumTest

//设置package包名称以及导入依赖的类
package io.scalajs.npm.bignum

import io.scalajs.nodejs.Assert
import org.scalatest.FunSpec

import scala.language.existentials


class BigNumTest extends FunSpec {

  describe("BigNum") {
    val v1 = "782910138827292261791972728324982"
    val v2 = "182373273283402171237474774728373"

    it("supports math functions") {
      val b = new BigNum(v1).add(500).sub(v2).div(8)

      info(s"new BigNum('$v1').add(500).sub('$v2').div(8) = $b")
      Assert.equal(b.toString(), "75067108192986261319312244199638")
    }

    it("supports math functions via operators") {
      val b = (new BigNum(v1) + 500 - v2) / 8

      info(s"(new BigNum('$v1') + 500 - '$v2')/8 = $b")
      Assert.equal(b.toString(), "75067108192986261319312244199638")
    }

    it("supports prime number detection") {
      for {
        n <- 0 to 100
        p = BigNum.pow(2, n) - 1 if p.probPrime(50)
      } {
        val perfect = p.mul(BigNum.pow(2, n - 1))
        info(perfect.toString)
      }
    }

  }

} 
开发者ID:scalajs-io,项目名称:bignum,代码行数:42,代码来源:BigNumTest.scala

示例4: FiledTest

//设置package包名称以及导入依赖的类
package io.scalajs.npm.filed

import io.scalajs.nodejs.Assert
import io.scalajs.nodejs.fs.Fs
import org.scalatest.FunSpec


class FiledTest extends FunSpec {
  val fileA = "./src/test/resources/fileA.txt"
  val fileB = "./src/test/resources/fileB.txt"
  val message = "Hello World"

  describe("Filed") {

    it("can pipe data from one stream to another") {
      info(s"Writing '$message' to Filed('$fileA')...")
      Fs.writeFileSync(fileA, message)

      info(s"Piping Filed('$fileA') to Filed('$fileB')...")
      Filed(fileA).pipe(Filed(fileB)).onEnd { () =>
        info(s"Verifying that Filed('$fileA') is identical to Filed('$fileB')")
        Assert.equal(Fs.readFileSync(fileB).toString(), message)
      }
    }

  }

} 
开发者ID:scalajs-io,项目名称:filed,代码行数:29,代码来源:FiledTest.scala

示例5: GzipUncompressedSizeTest

//设置package包名称以及导入依赖的类
package io.scalajs.npm.gzipuncompressedsize

import scalajs.concurrent.JSExecutionContext.Implicits.queue
import io.scalajs.nodejs.Assert
import org.scalatest.FunSpec

import scala.util.{Failure, Success}


class GzipUncompressedSizeTest extends FunSpec {

  describe("GzipUncompressedSize") {

    it("reports the uncompressed size of a gzip file via callback") {
      GzipUncompressedSize.fromFile("./README.md.gz", (error, uncompressedSize) => {
        Assert.equal(null, error)
        info(s"uncompressedSize = $uncompressedSize")
      })
    }

    it("reports the uncompressed size of a gzip file via a Scala Future") {
      GzipUncompressedSize.fromFileFuture("./README.md.gz") onComplete {
        case Success(uncompressedSize) =>
          info(s"uncompressedSize = $uncompressedSize")
        case Failure(e) =>
          alert(s"An error occurred: ${e.getMessage}")
      }
    }
  }

} 
开发者ID:scalajs-io,项目名称:gzip-uncompressed-size,代码行数:32,代码来源:GzipUncompressedSizeTest.scala


注:本文中的io.scalajs.nodejs.Assert类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。