package logic

import (
	"os"
	"strings"
	"testing"
	"time"
)

const (
	Output = `----------- SCAN SUMMARY -----------
Infected files: 0
Time: 0.981 sec (0 m 0 s)
Start Date: 2026:02:14 09:39:02
End Date:   2026:02:14 09:39:03`
)

func TestRegext(t *testing.T) {
	lines := strings.Split(Output, "\n")
	for _, i := range lines {
		if ReInfectedFile.MatchString(i) {
			f := ReInfectedFile.FindStringSubmatch(i)
			for _, ff := range f {
				t.Log(ff)
			}
		}
	}
}

func TestScanFile(t *testing.T) {
	target := "./hycusmutool"
	start := time.Now()
	have, err := ScanFile(target)
	dua := time.Since(start)

	if have {
		t.Logf("%s is bd", target)
	}

	t.Logf("used time: %dms", dua.Milliseconds())
	if err != nil {
		t.Error(err)
	}
}

func TestParseInt(t *testing.T) {
	i, err := ParseInt("abc")
	if err != nil {
		t.Error(err)
	}
	t.Logf("%d", i)
}

func TestPids(t *testing.T) {
	content, err := os.ReadFile("../../../asset/sftp.log")
	if err != nil {
		t.Error(err)
	}
	lines := strings.Split(string(content), "\n")
	start := time.Now()
	for _, v := range lines {
		if len(v) > 0 {
			_, err := ParseSftpLog(v)
			if err != nil {
				t.Error(err)
			}
		}
	}
	tt := time.Since(start)
	t.Logf("%d ms", tt.Milliseconds())
}
