github.com/dancsecs/gotomd@v0.0.0-20240310162206-65c4805cf510/markdown_test.go (about)

     1  /*
     2     Golang To Github Markdown Utility: gotomd
     3     Copyright (C) 2023, 2024 Leslie Dancsecs
     4  
     5     This program is free software: you can redistribute it and/or modify
     6     it under the terms of the GNU General Public License as published by
     7     the Free Software Foundation, either version 3 of the License, or
     8     (at your option) any later version.
     9  
    10     This program is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13     GNU General Public License for more details.
    14  
    15     You should have received a copy of the GNU General Public License
    16     along with this program.  If not, see <https://www.gnu.org/licenses/>.
    17  */
    18  
    19  package main
    20  
    21  import (
    22  	"testing"
    23  
    24  	"github.com/dancsecs/sztest"
    25  )
    26  
    27  func Test_Markdown_CleanMarkDownDocument(t *testing.T) {
    28  	chk := sztest.CaptureNothing(t)
    29  	defer chk.Release()
    30  
    31  	cleanDoc, err := cleanMarkDownDocument(
    32  		sztestBgnPrefix + szDocPrefix + "action1 -->\n" +
    33  			sztestEndPrefix + szTstPrefix + "action2 -->\n",
    34  	)
    35  
    36  	chk.Err(
    37  		err,
    38  		ErrTagOutOfSequence.Error()+
    39  			": \"<!--- gotomd::End::tst::action2 -->\"",
    40  	)
    41  	chk.Str(cleanDoc, "")
    42  }
    43  
    44  func Test_Markdown_CleanMarkDownDocumentMissingBlankAfterAuto(t *testing.T) {
    45  	chk := sztest.CaptureNothing(t)
    46  	defer chk.Release()
    47  
    48  	cleanDoc, err := cleanMarkDownDocument(
    49  		szAutoPrefix + " -->\nThis is not a blank line.",
    50  	)
    51  
    52  	chk.Err(
    53  		err,
    54  		ErrMissingHeaderLine.Error(),
    55  	)
    56  	chk.Str(cleanDoc, "")
    57  }
    58  
    59  func Test_Markdown_UpdateMarkDownDocument(t *testing.T) {
    60  	chk := sztest.CaptureNothing(t)
    61  	defer chk.Release()
    62  
    63  	updatedDoc, err := updateMarkDownDocument("",
    64  		sztestPrefix+szDocPrefix+"./INVALID_ROOT_DIRECTORY/action1 -->\n",
    65  	)
    66  
    67  	chk.Err(
    68  		err,
    69  		ErrInvalidDirectory.Error()+": \"./INVALID_ROOT_DIRECTORY\"",
    70  	)
    71  	chk.Str(updatedDoc, "")
    72  }
    73  
    74  func Test_Markdown_UpdateMarkDown_InvalidCommand(t *testing.T) {
    75  	chk := sztest.CaptureNothing(t)
    76  	defer chk.Release()
    77  
    78  	updatedDoc, err := updateMarkDownDocument("",
    79  		sztestPrefix+"unknownCommand -->\n",
    80  	)
    81  
    82  	chk.Err(
    83  		err,
    84  		ErrUnknownCommand.Error()+": \"<!--- gotomd::unknownCommand -->\"",
    85  	)
    86  	chk.Str(updatedDoc, "")
    87  }
    88  
    89  func Test_Markdown_Expand(t *testing.T) {
    90  	chk := sztest.CaptureLog(t)
    91  	defer chk.Release()
    92  
    93  	docInfo, err := getInfo("./example1", "TimesTwo")
    94  	chk.NoErr(err)
    95  
    96  	chk.Str(
    97  		expand(szDocPrefix,
    98  			"TimesTwo",
    99  			docInfo.declGoLang()+"\n\n"+
   100  				docInfo.docMarkdown(),
   101  		),
   102  		"<!--- gotomd::Bgn::doc::TimesTwo -->\n"+
   103  			"```go\nfunc TimesTwo(i int) int\n```\n"+
   104  			"\n"+
   105  			"TimesTwo returns the value times two.\n"+
   106  			"<!--- gotomd::End::doc::TimesTwo -->\n",
   107  	)
   108  
   109  	chk.Log(`getInfo("TimesTwo")`)
   110  }
   111  
   112  func Test_Markdown_Search(t *testing.T) {
   113  	chk := sztest.CaptureNothing(t)
   114  	defer chk.Release()
   115  
   116  	chk.Int(action.search("a"), -1)
   117  	chk.Int(action.search("z"), -1)
   118  }