ROOTPLOIT
Server: LiteSpeed
System: Linux in-mum-web1878.main-hosting.eu 5.14.0-570.21.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 11 07:22:35 EDT 2025 x86_64
User: u435929562 (435929562)
PHP: 7.4.33
Disabled: system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //opt/golang/1.22.0/src/internal/dag/parse_test.go
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package dag

import (
	"reflect"
	"strings"
	"testing"
)

const diamond = `
NONE < a < b, c < d;
`

func mustParse(t *testing.T, dag string) *Graph {
	t.Helper()
	g, err := Parse(dag)
	if err != nil {
		t.Fatal(err)
	}
	return g
}

func wantEdges(t *testing.T, g *Graph, edges string) {
	t.Helper()

	wantEdges := strings.Fields(edges)
	wantEdgeMap := make(map[string]bool)
	for _, e := range wantEdges {
		wantEdgeMap[e] = true
	}

	for _, n1 := range g.Nodes {
		for _, n2 := range g.Nodes {
			got := g.HasEdge(n1, n2)
			want := wantEdgeMap[n1+"->"+n2]
			if got && want {
				t.Logf("%s->%s", n1, n2)
			} else if got && !want {
				t.Errorf("%s->%s present but not expected", n1, n2)
			} else if want && !got {
				t.Errorf("%s->%s missing but expected", n1, n2)
			}
		}
	}
}

func TestParse(t *testing.T) {
	// Basic smoke test for graph parsing.
	g := mustParse(t, diamond)

	wantNodes := strings.Fields("a b c d")
	if !reflect.DeepEqual(wantNodes, g.Nodes) {
		t.Fatalf("want nodes %v, got %v", wantNodes, g.Nodes)
	}

	// Parse returns the transitive closure, so it adds d->a.
	wantEdges(t, g, "b->a c->a d->a d->b d->c")
}