Skip to content

Commit a9e5752

Browse files
committed
♻️ ioutil 文件读取使用 os
1 parent 43df094 commit a9e5752

File tree

8 files changed

+27
-21
lines changed

8 files changed

+27
-21
lines changed

benchmark/benchmark_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
package main
1212

1313
import (
14-
"io/ioutil"
14+
"os"
1515
"testing"
1616

1717
"github.com/88250/lute"
@@ -20,7 +20,7 @@ import (
2020
const spec = "commonmark-spec"
2121

2222
func BenchmarkLute(b *testing.B) {
23-
buf, err := ioutil.ReadFile(spec + ".md")
23+
buf, err := os.ReadFile(spec + ".md")
2424
if nil != err {
2525
b.Fatalf("read spec text failed: " + err.Error())
2626
}
@@ -43,7 +43,7 @@ func BenchmarkLute(b *testing.B) {
4343
if nil != err {
4444
b.Fatalf("unexpected: %s", err)
4545
}
46-
if err := ioutil.WriteFile(spec+".html", output, 0644); nil != err {
46+
if err := os.WriteFile(spec+".html", output, 0644); nil != err {
4747
b.Fatalf("write spec html failed: %s", err)
4848
}
4949

chroma-styles/main.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ package main
1313
import (
1414
"bytes"
1515
"fmt"
16-
"io/ioutil"
1716
"path/filepath"
1817
"strings"
1918

@@ -30,7 +29,7 @@ func main() {
3029
names := styles.Names()
3130
for _, name := range names {
3231
formatter.WriteCSS(&b, styles.Get(name))
33-
ioutil.WriteFile(filepath.Join(dir, name)+".css", b.Bytes(), 0644)
32+
os.WriteFile(filepath.Join(dir, name)+".css", b.Bytes(), 0644)
3433
b.Reset()
3534
}
3635

pprof/main.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
package main
1212

1313
import (
14-
"io/ioutil"
1514
"os"
1615
"runtime/pprof"
1716

@@ -20,7 +19,7 @@ import (
2019

2120
func main() {
2221
spec := "test/commonmark-spec"
23-
bytes, err := ioutil.ReadFile(spec + ".md")
22+
bytes, err := os.ReadFile(spec + ".md")
2423
if nil != err {
2524
panic(err)
2625
}

test/code_syntax_highlight_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
package test
1212

1313
import (
14-
"io/ioutil"
14+
"os"
1515
"strings"
1616
"testing"
1717

@@ -22,7 +22,7 @@ func TestCodeSyntaxHighlightIssue17(t *testing.T) {
2222
// 语法高亮支持内联样式 https://github.com/b3log/lute/issues/17
2323

2424
caseName := "code-syntax-highlight-issue17"
25-
data, err := ioutil.ReadFile(caseName + ".md")
25+
data, err := os.ReadFile(caseName + ".md")
2626
if nil != err {
2727
t.Fatalf("read case failed: %s", err)
2828
}
@@ -47,14 +47,14 @@ func TestCodeSyntaxHighlightIssue17(t *testing.T) {
4747
t.Fatalf("test case [%s] failed\nexpected\n\t%q\ngot\n\t%q\n", caseName, expected, html)
4848
}
4949

50-
data, err = ioutil.ReadFile(caseName + ".tpl")
50+
data, err = os.ReadFile(caseName + ".tpl")
5151
if nil != err {
5252
t.Fatalf("read template failed: %s", err)
5353
}
5454
template := string(data)
5555
template = strings.ReplaceAll(template, "${style}", style)
5656
template = strings.ReplaceAll(template, "${code}", html)
57-
ioutil.WriteFile(caseName+".html", []byte(template), 0644)
57+
os.WriteFile(caseName+".html", []byte(template), 0644)
5858
}
5959

6060
var codeSyntaxHighlightLineNumTests = []parseTest{

test/commonmark_spec_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ package test
1212

1313
import (
1414
"encoding/json"
15-
"io/ioutil"
15+
"os"
1616
"strconv"
1717
"testing"
1818

@@ -29,7 +29,7 @@ type testcase struct {
2929
}
3030

3131
func TestSpec(t *testing.T) {
32-
bytes, err := ioutil.ReadFile("commonmark-spec.json")
32+
bytes, err := os.ReadFile("commonmark-spec.json")
3333
if nil != err {
3434
t.Fatalf("read spec test cases failed: " + err.Error())
3535
}

test/format_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
package test
1212

1313
import (
14-
"io/ioutil"
14+
"os"
1515
"strings"
1616
"testing"
1717

@@ -113,7 +113,7 @@ func TestFormat(t *testing.T) {
113113
}
114114

115115
func TestFormatCases(t *testing.T) {
116-
files, err := ioutil.ReadDir(".")
116+
files, err := os.ReadDir(".")
117117
if nil != err {
118118
t.Fatalf("read test dir failed: %s", err)
119119
}
@@ -130,7 +130,7 @@ func TestFormatCases(t *testing.T) {
130130
}
131131

132132
caseName := file.Name()[:len(file.Name())-3]
133-
bytes, err := ioutil.ReadFile(caseName + ".md")
133+
bytes, err := os.ReadFile(caseName + ".md")
134134
if nil != err {
135135
t.Fatalf("read case failed: %s", err)
136136
}
@@ -140,7 +140,7 @@ func TestFormatCases(t *testing.T) {
140140
htmlBytes := luteEngine.Format(caseName+".md", bytes)
141141
html := string(htmlBytes)
142142

143-
bytes, err = ioutil.ReadFile(caseName + "-formatted.md")
143+
bytes, err = os.ReadFile(caseName + "-formatted.md")
144144
if nil != err {
145145
t.Fatalf("read case cailed: %s", err)
146146
}

test/parallel_test.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,22 @@
1010

1111
package test
1212

13+
//
14+
//import (
15+
// "os"
16+
// "sync"
17+
// "testing"
18+
//
19+
// "github.com/88250/lute"
20+
//)
1321
//
1422
//func TestParallel(t *testing.T) {
15-
// data0, err := ioutil.ReadFile("../test/commonmark-spec.md")
23+
// data0, err := os.ReadFile("../test/commonmark-spec.md")
1624
// if nil != err {
1725
// t.Fatalf("read test text failed: " + err.Error())
1826
// }
1927
//
20-
// data1, err := ioutil.ReadFile("../test/case1.md")
28+
// data1, err := os.ReadFile("../test/case1.md")
2129
// if nil != err {
2230
// t.Fatalf("read test text failed: " + err.Error())
2331
// }

test/parse_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
package test
1212

1313
import (
14-
"io/ioutil"
14+
"os"
1515
"testing"
1616

1717
"github.com/88250/lute"
@@ -279,7 +279,7 @@ func TestParse(t *testing.T) {
279279
}
280280

281281
func TestCase1(t *testing.T) {
282-
bytes, err := ioutil.ReadFile("case1.md")
282+
bytes, err := os.ReadFile("case1.md")
283283
if nil != err {
284284
t.Fatalf("read case failed: %s", err)
285285
}

0 commit comments

Comments
 (0)