github.com/wheelercj/pm2md@v0.0.11/cmd/func_map_test.go (about)

     1  // Copyright 2023 Chris Wheeler
     2  
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  
     7  // 	http://www.apache.org/licenses/LICENSE-2.0
     8  
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package cmd
    16  
    17  import (
    18  	"fmt"
    19  	"testing"
    20  )
    21  
    22  func TestFormatHeaderLink(t *testing.T) {
    23  	tests := []struct {
    24  		input, want string
    25  	}{
    26  		{"", "[](#)"},
    27  		{"create account", "[create account](#create-account)"},
    28  		{"sample request body", "[sample request body](#sample-request-body)"},
    29  		{"sample request body", "[sample request body](#sample-request-body-1)"},
    30  		{"sample request body", "[sample request body](#sample-request-body-2)"},
    31  	}
    32  
    33  	for i, test := range tests {
    34  		name := fmt.Sprintf("(%d) %q", i, test.input)
    35  		t.Run(name, func(t *testing.T) {
    36  			ans := formatHeaderLink(test.input)
    37  			if ans != test.want {
    38  				t.Errorf("formatHeaderLink(%q) = %q, want %q", test.input, ans, test.want)
    39  			}
    40  		})
    41  	}
    42  }
    43  
    44  func TestFormatHeaderPath(t *testing.T) {
    45  	tests := []struct {
    46  		input, want string
    47  	}{
    48  		{"with space", "#with-space"},
    49  		{" with spaces ", "#with-spaces-"},
    50  		{"special@#$%^&+*()=/\\|'\":;!?.>,<[]{}`~characters", "#specialcharacters"},
    51  		{"dash-and_underscore", "#dash-and_underscore"},
    52  		{"UPPERCASE", "#uppercase"},
    53  		{"123", "#123"},
    54  		{"课客果国", "#课客果国"},
    55  		{"", "#"},
    56  	}
    57  
    58  	for _, test := range tests {
    59  		t.Run(test.want, func(t *testing.T) {
    60  			ans := formatHeaderPath(test.input)
    61  			if ans != test.want {
    62  				t.Errorf("formatHeaderPath(%q) = %q, want %q", test.input, ans, test.want)
    63  			}
    64  		})
    65  	}
    66  }