aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/git/test_git.js
blob: c18d0841f970dedf260339c366636624c8f83059 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// Run: node desktop/modules/git/test_git.js
// Git.js is a QML library, so its .pragma line is stripped before node
// evaluates it.

const fs = require("fs");
const assert = require("assert");

const src = fs.readFileSync(__dirname + "/Git.js", "utf8")
    .replace(/^\.pragma library$/m, "");
const G = new Function(src + "\nreturn { parse };")();

// `gitcfg list` output: name, newline, value, NUL. A subsection's dots stay
// in the section; a value keeps its = and its own newlines; a valueless
// boolean has no newline at all.
assert.deepStrictEqual(G.parse("user.name\nJane D.\0color.branch.remote\nyellow\0"
                               + "alias.x\n!f() { a=1\nb; }\0x.flag\0"), [
    { name: "user.name", section: "user", key: "name", value: "Jane D." },
    { name: "color.branch.remote", section: "color.branch", key: "remote", value: "yellow" },
    { name: "alias.x", section: "alias", key: "x", value: "!f() { a=1\nb; }" },
    { name: "x.flag", section: "x", key: "flag", value: "" },
]);
// No config file: gitcfg prints nothing.
assert.deepStrictEqual(G.parse(""), []);

console.log("test_git: ok");