forked from go-openapi/testify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdifflib.go
More file actions
49 lines (37 loc) · 1.66 KB
/
difflib.go
File metadata and controls
49 lines (37 loc) · 1.66 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
// SPDX-FileCopyrightText: Copyright 2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0
// Package difflib provides a unified diff for sequences of strings.
//
// It exposes the unified diff formatter used internally by [github.com/go-openapi/testify/v2].
package difflib
import (
"io"
idifflib "github.com/go-openapi/testify/v2/internal/difflib"
)
// SplitLines splits a string on "\n" while preserving them. The output can be used
// as input for the [UnifiedDiff] structure.
func SplitLines(s string) []string {
return idifflib.SplitLines(s)
}
// UnifiedDiff holds the unified diff parameters.
type UnifiedDiff = idifflib.UnifiedDiff
// Options to fine-tune the rendering of the diff output.
type Options = idifflib.Options
// Formatter is a formatting function like [fmt.Printf].
type Formatter = idifflib.Formatter
// Printer outputs a formatted string, e.g. to some underlying writer.
type Printer idifflib.Printer
// FormatterBuilder is a function that builds a [Formatter] given a buffered [bufio.Writer].
type FormatterBuilder = idifflib.FormatterBuilder
// PrinterBuilder is a function that builds a [Printer] given a buffered [bufio.Writer].
type PrinterBuilder = idifflib.PrinterBuilder
// GetUnifiedDiffString is like [WriteUnifiedDiff] but returns the diff as a string instead of writing to an [io.Writer].
func GetUnifiedDiffString(diff UnifiedDiff) (string, error) {
return idifflib.GetUnifiedDiffString(diff)
}
// WriteUnifiedDiff writes the comparison between two sequences of lines.
//
// It generates the delta as a unified diff.
func WriteUnifiedDiff(writer io.Writer, diff UnifiedDiff) error {
return idifflib.WriteUnifiedDiff(writer, diff)
}