V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
moonbitlang
V2EX  ›  编程

MoonBit 支持 expect testing 与多参数构造器

  •  
  •   moonbitlang · 34 天前 · 432 次点击
    这是一个创建于 34 天前的主题,其中的信息可能已经有所发展或是发生改变。

    构建系统更新

    1. 支持 expect testing

    a. 使用 moon new 新建一个 MoonBit 项目。

    b. 在 lib/hello.mbt 中写入:

    pub fn hello() -> String {
      "Hello, world!"
    }
    
    test {
      let buf = Buffer::make(10)
      buf.write_string(hello())
      buf.expect()?
    }
    
    

    c. 然后运行 moon test --update 或者 moon test -u:

    $ moon test --update
    expect test failed at lib/hello.mbt:8:3-8:15
    Diff:
    ----
    Hello, world!
    ----
    
    Total tests: 1, passed: 0, failed: 1.
    
    Auto updating expect tests and retesting ...
    
    Total tests: 1, passed: 1, failed: 0.
    
    

    d. 再次打开 lib/hello.mbt 文件,可以看到已经将测试结果 promote 到源码中。

    pub fn hello() -> String {
      "Hello, world!"
    }
    
    test {
      let buf = Buffer::make(10)
      buf.write_string(hello())
      buf.expect(~content="Hello, world!")?
      //         ^~~~~~~~~~~~~~~~~~~~~~~~ 测试结果更新
    }
    
    

    2. moon run 不再支持 --output-wat 选项。

    MoonBit 更新

    1. 支持多参数构造器的后端代码生成

    支持多参数构造器( multi-argument constructor )的后端代码生成。现在构造一个泛型类型的值的时候,如果泛型参数为元组的话必须要写括号,即:

    enum A[X] {
      A(X)
    }
    
    fn init {
      // Error, expecting 1 arg, getting 2
      A::A(1, 2) |> ignore
    
      // Ok
      A::A((1, 2)) |> ignore
    }
    
    

    多参数构造器 unbox 了参数,能够提高生成的代码的性能,也允许程序员对数据的内存布局有了更多的掌控。

    2. 调整了 Int64 的 lsl, lsr, asr 方法

    现在移位参数不再是 Int64 ,而是 Int 。同时调整了 clz, ctz, popcnt 方法,现在返回类型不再是 Int64 ,而是 Int 。此项改变有助于我们在不支持原生 Int64 的平台上生成更高效的代码。

    IDE 更新

    1. 支持带标签参数的重命名。

    2. VSCode 插件支持自动安装或者更新 MoonBit

    a. 更新插件后,如果没有安装 moon 或者 moon 不是最新的时候,VSCode 右下角弹出自动安装/升级的提示。

    image.png

    b. 点击 "yes", 来执行自动安装任务。任务完成后就可以用了。

    image.png

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1796 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 16:31 · PVG 00:31 · LAX 09:31 · JFK 12:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.