// E2E 测试：Buffer 模块
import { Buffer } from "buffer";

function main(): number {
    // Test Buffer.from(string)
    let buf1 = Buffer.from("hello");
    print("buf1 length: " + buf1.length);

    // Test Buffer.alloc(size)
    let buf2 = Buffer.alloc(10);
    print("buf2 length: " + buf2.length);

    // Test Buffer.toString()
    let buf3 = Buffer.from("world");
    let str = buf3.toString();
    print("buf3 toString: " + str);

    // Test Buffer.concat()
    let bufs = [Buffer.from("hello"), Buffer.from(" "), Buffer.from("world")];
    let combined = Buffer.concat(bufs);
    print("combined: " + combined.toString());

    // 验证结果
    if (buf1.length == 5 && buf2.length == 10 && str == "world") {
        return 1;
    }
    return 0;
}
