PathrockNetwork Gno Explorer
HomeBlocksTransactionsRealmsPackagesValidatorsAnalytics

PathrockNetwork Gno Explorer — an independent explorer for Gno.land Mainnet (gnoland-1), operated by PathrockNetwork. Not an official Gno.land service.

gnowebarchive RPC

gno.land/p/moul/mdtable/v0

Package
Open in gnoweb ↗

Overview

Kind
Pure package
Name
v0
Namespace
moul / mdtable
Files
3 (gnomod.toml)
Exported functions
n/a — not supported for pure packages by the node (vm/qfuncs)
Module
gno.land/p/moul/mdtable/v0
gno
0.9

Files (3)

  • gnomod.tomltoml
  • mdtable.gnogno
  • mdtable_test.gnogno
mdtable_test.gnogno
1package mdtable_test23import (4	"testing"56	"gno.land/p/moul/mdtable/v0"7	"gno.land/p/nt/urequire/v0"8)910// XXX: switch to `func Example() {}` when supported.11func TestExample(t *testing.T) {12	table := mdtable.Table{13		Headers: []string{"ID", "Title", "Status"},14		Rows: [][]string{15			{"#1", "Add a new validator", "succeed"},16			{"#2", "Change parameter", "timed out"},17			{"#3", "Fill pool", "active"},18		},19	}2021	got := table.String()22	expected := `| ID | Title | Status |23| --- | --- | --- |24| #1 | Add a new validator | succeed |25| #2 | Change parameter | timed out |26| #3 | Fill pool | active |27`2829	urequire.Equal(t, got, expected)30}3132func TestTableString(t *testing.T) {33	tests := []struct {34		name     string35		table    mdtable.Table36		expected string37	}{38		{39			name: "With Headers and Rows",40			table: mdtable.Table{41				Headers: []string{"ID", "Title", "Status", "Date"},42				Rows: [][]string{43					{"#1", "Add a new validator", "succeed", "2024-01-01"},44					{"#2", "Change parameter", "timed out", "2024-01-02"},45				},46			},47			expected: `| ID | Title | Status | Date |48| --- | --- | --- | --- |49| #1 | Add a new validator | succeed | 2024-01-01 |50| #2 | Change parameter | timed out | 2024-01-02 |51`,52		},53		{54			name: "Without Headers",55			table: mdtable.Table{56				Rows: [][]string{57					{"#1", "Add a new validator", "succeed", "2024-01-01"},58					{"#2", "Change parameter", "timed out", "2024-01-02"},59				},60			},61			expected: `|  |  |  |  |62| --- | --- | --- | --- |63| #1 | Add a new validator | succeed | 2024-01-01 |64| #2 | Change parameter | timed out | 2024-01-02 |65`,66		},67		{68			name: "Without Rows",69			table: mdtable.Table{70				Headers: []string{"ID", "Title", "Status", "Date"},71			},72			expected: `| ID | Title | Status | Date |73| --- | --- | --- | --- |74`,75		},76		{77			name: "With Pipe Character in Content",78			table: mdtable.Table{79				Headers: []string{"ID", "Title", "Status", "Date"},80				Rows: [][]string{81					{"#1", "Add a new | validator", "succeed", "2024-01-01"},82					{"#2", "Change parameter", "timed out", "2024-01-02"},83				},84			},85			expected: `| ID | Title | Status | Date |86| --- | --- | --- | --- |87| #1 | Add a new | validator | succeed | 2024-01-01 |88| #2 | Change parameter | timed out | 2024-01-02 |89`,90		},91		{92			name: "With Varying Row Sizes", // XXX: should we have a different behavior?93			table: mdtable.Table{94				Headers: []string{"ID", "Title"},95				Rows: [][]string{96					{"#1", "Add a new validator"},97					{"#2", "Change parameter", "Extra Column"},98					{"#3", "Fill pool"},99				},100			},101			expected: `| ID | Title |102| --- | --- |103| #1 | Add a new validator |104| #2 | Change parameter | Extra Column |105| #3 | Fill pool |106`,107		},108		{109			name: "With UTF-8 Characters",110			table: mdtable.Table{111				Headers: []string{"ID", "Title", "Status", "Date"},112				Rows: [][]string{113					{"#1", "Café", "succeed", "2024-01-01"},114					{"#2", "München", "timed out", "2024-01-02"},115					{"#3", "São Paulo", "active", "2024-01-03"},116				},117			},118			expected: `| ID | Title | Status | Date |119| --- | --- | --- | --- |120| #1 | Café | succeed | 2024-01-01 |121| #2 | München | timed out | 2024-01-02 |122| #3 | São Paulo | active | 2024-01-03 |123`,124		},125		{126			name:     "With no Headers and no Rows",127			table:    mdtable.Table{},128			expected: ``,129		},130	}131132	for _, tt := range tests {133		t.Run(tt.name, func(t *testing.T) {134			got := tt.table.String()135			urequire.Equal(t, got, tt.expected)136		})137	}138}139140func TestTableAppend(t *testing.T) {141	table := mdtable.Table{142		Headers: []string{"ID", "Title", "Status", "Date"},143	}144145	// Use the Append method to add rows to the table146	table.Append([]string{"#1", "Add a new validator", "succeed", "2024-01-01"})147	table.Append([]string{"#2", "Change parameter", "timed out", "2024-01-02"})148	table.Append([]string{"#3", "Fill pool", "active", "2024-01-03"})149	got := table.String()150151	expected := `| ID | Title | Status | Date |152| --- | --- | --- | --- |153| #1 | Add a new validator | succeed | 2024-01-01 |154| #2 | Change parameter | timed out | 2024-01-02 |155| #3 | Fill pool | active | 2024-01-03 |156`157	urequire.Equal(t, got, expected)158}159

Functions

not supported for pure packages by the node (vm/qfuncs)

Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.