mirror of
https://github.com/NullHypothesis/censorbib.git
synced 2025-07-25 15:35:55 -04:00
Add new build tool.
bibliogra.py requires Python 2, which is a pain to deal with. This commit adds a Go tool that compiles CensorBib from BibTeX to HTML. The tool does the bare minimum and is quite strict in the BibTeX format it expects.
This commit is contained in:
parent
d432134ed4
commit
4be5f7bfb2
21 changed files with 2381 additions and 0 deletions
43
src/main_test.go
Normal file
43
src/main_test.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/nickng/bibtex"
|
||||
)
|
||||
|
||||
func mustParse(t *testing.T, s string) bibEntry {
|
||||
t.Helper()
|
||||
bib, err := bibtex.Parse(strings.NewReader(s))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to parse bibtex: %v", err)
|
||||
}
|
||||
return bibEntry{
|
||||
BibEntry: *bib.Entries[0],
|
||||
lineNum: 0,
|
||||
}
|
||||
}
|
||||
|
||||
func TestRun(t *testing.T) {
|
||||
buf := bytes.NewBufferString("")
|
||||
entry := mustParse(t, `@inproceedings{Almutairi2024a,
|
||||
author = {Sultan Almutairi and Yogev Neumann and Khaled Harfoush},
|
||||
title = {Fingerprinting {VPNs} with Custom Router Firmware: A New Censorship Threat Model},
|
||||
booktitle = {Consumer Communications \& Networking Conference},
|
||||
publisher = {IEEE},
|
||||
year = {2024},
|
||||
url = {https://censorbib.nymity.ch/pdf/Almutairi2024a.pdf},
|
||||
}`)
|
||||
|
||||
makeBib(buf, []bibEntry{entry})
|
||||
|
||||
bufStr := buf.String()
|
||||
if !strings.HasPrefix(bufStr, "<ul>") {
|
||||
t.Errorf("expected <ul> but got %q...", bufStr[:10])
|
||||
}
|
||||
if !strings.HasSuffix(bufStr, "</ul>\n") {
|
||||
t.Errorf("expected </ul> but got %q", bufStr[len(bufStr)-10:])
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue