HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/zaklada/html/node_modules/simple-fmt/test/simple-fmt-tests.js
"use strict";

var test = require("tap").test;
var fmt = require("../");

test("fmt", function(t) {
    t.equals(fmt("all your {0} are belong to {1}", "base", "us"),
        "all your base are belong to us");

    var obj = {
        toString: function() {
            return "yoyoma";
        },
    };

    t.equals(fmt("object is called {0} and is {1} ms old", obj, 1),
        "object is called yoyoma and is 1 ms old");

    t.equals(fmt("no arguments => no modifs {0} {1}"),
        "no arguments => no modifs {0} {1}");

    t.end();
});

test("fmt.obj", function(t) {
    var obj2 = {
        name: "yoyoma",
        age: 1,
    };

    t.equals(fmt.obj("object is called {name} and is {age} ms old", obj2),
        "object is called yoyoma and is 1 ms old");

    t.equals(fmt.obj("no matching properties => no modifs {0} {1} {name} {age}", {}),
        "no matching properties => no modifs {0} {1} {name} {age}");

    t.equals(fmt.obj("works for arrays too: [{2}, {1}, {0}]", ["one", "two", "three"]),
        "works for arrays too: [three, two, one]");

    t.end();
});

test("fmt.repeat", function(t) {
    t.equals(fmt.repeat("*", 3), "***");
    t.equals(fmt.repeat("*", 0), "");
    t.equals(fmt.repeat("", 3), "");

    t.end();
});