XU XUv0.16.0

#testing/fstest

导入方式: #testing/fstest

公开 API: 2 函数, 5 方法, 2 类型, 0 常量, 0 方法集

内存 MapFS 与一致性检查。

struct MapFile

XuAPI
pub struct MapFile {
    pub name string
    pub body string
    pub dir bool
}

用途

承载 name、body、dir 等属性的结构体。

公开字段

name string
名字
body string
正文
dir bool
目录

struct MapFS

XuAPI
pub struct MapFS {
    pub files []MapFile
}

用途

承载 files 等属性的结构体。

公开字段

files []MapFile
字段([]MapFile)

map_fs

XuAPI
pub fn map_fs() MapFS

用途

构造基于内存映射字典的 MapFS 虚拟测试文件系统。

参数

无需传入参数。

返回值

MapFS — 该类型的值

($&MapFS) add

XuAPI
pub fn (fs $&MapFS) add(name string, body string)

用途

$&MapFS 上的操作:相加。

参数

fs $&MapFS
本次调用使用的 MapFS 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
name string
名字(string)
body string
正文(string)

返回值

不返回值。

($&MapFS) add_dir

XuAPI
pub fn (fs $&MapFS) add_dir(name string)

用途

$&MapFS 上的操作:增加目录部分。

参数

fs $&MapFS
本次调用使用的 MapFS 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
name string
名字(string)

返回值

不返回值。

(MapFS) read_file

XuAPI
pub fn (fs MapFS) read_file(name string) string

用途

MapFS 上的操作:读文件。失败时抛出错误,调用方需处理或继续传播。

参数

fs MapFS
本次调用使用的 MapFS 实例;按值接收。
name string
名字(string)

返回值

string — 结果字符串

(MapFS) stat_dir

XuAPI
pub fn (fs MapFS) stat_dir(name string) bool

用途

MapFS 上的操作:元信息目录部分。

参数

fs MapFS
本次调用使用的 MapFS 实例;按值接收。
name string
名字(string)

返回值

bool — 是否成立

(MapFS) has

XuAPI
pub fn (fs MapFS) has(name string) bool

用途

MapFS 上的操作:是否具有。

参数

fs MapFS
本次调用使用的 MapFS 实例;按值接收。
name string
名字(string)

返回值

bool — 是否成立

test

XuAPI
pub fn test(fs &MapFS) int

用途

test: 路径合法、文件可读、目录可 stat( TestFS 的常见失败点)。失败时抛出错误,调用方需处理或继续传播。

参数

fs &MapFS
fs(只读借用,调用方仍持有原值;类型 &MapFS)

返回值

int — 该类型的值