github.com/anakojm/hugo-katex@v0.0.0-20231023141351-42d6f5de9c0b/parser/metadecoders/format_test.go (about)

     1  // Copyright 2018 The Hugo Authors. All rights reserved.
     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  // http://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software
     9  // distributed under the License is distributed on an "AS IS" BASIS,
    10  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package metadecoders
    15  
    16  import (
    17  	"testing"
    18  
    19  	qt "github.com/frankban/quicktest"
    20  )
    21  
    22  func TestFormatFromString(t *testing.T) {
    23  	c := qt.New(t)
    24  	for _, test := range []struct {
    25  		s      string
    26  		expect Format
    27  	}{
    28  		{"json", JSON},
    29  		{"yaml", YAML},
    30  		{"yml", YAML},
    31  		{"xml", XML},
    32  		{"toml", TOML},
    33  		{"config.toml", TOML},
    34  		{"tOMl", TOML},
    35  		{"org", ORG},
    36  		{"foo", ""},
    37  	} {
    38  		c.Assert(FormatFromString(test.s), qt.Equals, test.expect)
    39  	}
    40  }
    41  
    42  func TestFormatFromContentString(t *testing.T) {
    43  	t.Parallel()
    44  	c := qt.New(t)
    45  
    46  	for i, test := range []struct {
    47  		data   string
    48  		expect any
    49  	}{
    50  		{`foo = "bar"`, TOML},
    51  		{`   foo = "bar"`, TOML},
    52  		{`foo="bar"`, TOML},
    53  		{`foo: "bar"`, YAML},
    54  		{`foo:"bar"`, YAML},
    55  		{`{ "foo": "bar"`, JSON},
    56  		{`a,b,c"`, CSV},
    57  		{`<foo>bar</foo>"`, XML},
    58  		{`asdfasdf`, Format("")},
    59  		{``, Format("")},
    60  	} {
    61  		errMsg := qt.Commentf("[%d] %s", i, test.data)
    62  
    63  		result := Default.FormatFromContentString(test.data)
    64  
    65  		c.Assert(result, qt.Equals, test.expect, errMsg)
    66  	}
    67  }