-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadme_test.go
More file actions
191 lines (157 loc) · 5.61 KB
/
Copy pathreadme_test.go
File metadata and controls
191 lines (157 loc) · 5.61 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package main
import (
"os"
"strings"
"testing"
)
func TestREADMEHeader(t *testing.T) {
// Read the README.md file
content, err := os.ReadFile("README.md")
if err != nil {
t.Fatalf("Failed to read README.md: %v", err)
}
readmeContent := string(content)
// Test 1: Project name "ZIM Reader" is displayed prominently
if !strings.Contains(readmeContent, "# ZIM Reader") {
t.Error("README.md does not contain project name 'ZIM Reader' prominently at top")
}
// Test 2: Contains a one-paragraph project description
descriptionFound := false
for _, line := range strings.Split(readmeContent, "\n") {
trimmedLine := strings.TrimSpace(line)
if trimmedLine != "" && !strings.HasPrefix(trimmedLine, "#") && !strings.Contains(trimmedLine, "![") {
// Found a non-empty line that's not a header and not a badge
descriptionFound = true
break
}
}
if !descriptionFound {
t.Error("README.md does not contain a one-paragraph project description")
}
// Test 3: Contains the tagged install command.
if !strings.Contains(readmeContent, "go install github.com/dotcommander/zim@v0.1.3") {
t.Error("README.md does not contain the tagged install command")
}
if strings.Contains(readmeContent, "[![License]") {
t.Error("README.md must not contain a license badge")
}
}
func TestREADMEFeatures(t *testing.T) {
// Read the README.md file
content, err := os.ReadFile("README.md")
if err != nil {
t.Fatalf("Failed to read README.md: %v", err)
}
readmeContent := string(content)
// Test 1: Features section exists
if !strings.Contains(readmeContent, "## Features") {
t.Fatal("README.md does not contain a '## Features' section")
}
// Extract features section
inFeaturesSection := false
featureBullets := []string{}
for _, line := range strings.Split(readmeContent, "\n") {
trimmedLine := strings.TrimSpace(line)
if strings.HasPrefix(trimmedLine, "## Features") {
inFeaturesSection = true
continue
}
if inFeaturesSection && strings.HasPrefix(trimmedLine, "## ") {
// Reached next section, stop collecting
break
}
if inFeaturesSection && strings.HasPrefix(trimmedLine, "- ") {
featureBullets = append(featureBullets, trimmedLine)
}
}
// Test 2: At least 6 feature bullet points
if len(featureBullets) < 6 {
t.Errorf("README.md features section has only %d bullet points, expected at least 6", len(featureBullets))
}
// Test 3: Each feature is described in one concise sentence
for i, feature := range featureBullets {
// Remove markdown formatting
cleanFeature := strings.ReplaceAll(feature, "**", "")
cleanFeature = strings.TrimPrefix(cleanFeature, "- ")
// Check for reasonable length (not too long) - primary conciseness check
if len(cleanFeature) > 150 {
t.Errorf("Feature %d is too long (%d chars), should be more concise", i+1, len(cleanFeature))
}
// Check that it reads like a single sentence (has a subject and predicate)
// Split by colon to get feature name and description
parts := strings.SplitN(cleanFeature, ":", 2)
if len(parts) != 2 {
t.Errorf("Feature %d should be in format 'feature: description'", i+1)
continue
}
description := strings.TrimSpace(parts[1])
// Description should end with a period
if !strings.HasSuffix(description, ".") {
t.Errorf("Feature %d description should end with a period", i+1)
}
// Check for obvious multiple sentences (looking for mid-sentence periods)
// Count periods in the middle of the description (not at the end)
midDescription := strings.TrimSuffix(description, ".")
midPeriodCount := strings.Count(midDescription, ".")
// Allow periods in abbreviations, file paths, etc.
// We'll be lenient since the length check ensures conciseness
if midPeriodCount > 2 {
t.Errorf("Feature %d may have multiple sentences (%d mid-sentence periods)", i+1, midPeriodCount)
}
}
// Test 4: Features include required categories
requiredKeywords := []string{"read", "search", "serve", "index", "library"}
featureText := strings.ToLower(strings.Join(featureBullets, " "))
for _, keyword := range requiredKeywords {
if !strings.Contains(featureText, keyword) {
t.Errorf("Features section does not mention '%s' capability", keyword)
}
}
}
func TestREADMELicense(t *testing.T) {
content, err := os.ReadFile("README.md")
if err != nil {
t.Fatalf("Failed to read README.md: %v", err)
}
readmeContent := string(content)
// Test 1: License section exists and links to the repository license.
if !strings.Contains(readmeContent, "## License") {
t.Fatal("README.md does not contain a '## License' section")
}
// Extract license section
inLicenseSection := false
licenseContent := ""
for _, line := range strings.Split(readmeContent, "\n") {
trimmedLine := strings.TrimSpace(line)
if strings.HasPrefix(trimmedLine, "## License") {
inLicenseSection = true
continue
}
if inLicenseSection && strings.HasPrefix(trimmedLine, "## ") {
// Reached next section, stop collecting
break
}
if inLicenseSection {
licenseContent += trimmedLine + "\n"
}
}
licenseLower := strings.ToLower(licenseContent)
if !strings.Contains(licenseLower, "mit license") || !strings.Contains(licenseContent, "[MIT License](LICENSE)") {
t.Error("License section must link to the MIT LICENSE file")
}
// Test 2: LICENSE contains the expected MIT grant and copyright owner.
license, err := os.ReadFile("LICENSE")
if err != nil {
t.Fatal(err)
}
for _, want := range []string{
"MIT License",
"Copyright (c) 2026 Gary Blankenship",
"Permission is hereby granted, free of charge",
`THE SOFTWARE IS PROVIDED "AS IS"`,
} {
if !strings.Contains(string(license), want) {
t.Errorf("LICENSE missing %q", want)
}
}
}