package com.ruoyi.generator.service.front;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class AiDatabaseSchemaValidatorTest
{
    private final AiDatabaseSchemaValidator validator = new AiDatabaseSchemaValidator();

    @Test
    public void validatesNamesColumnTypesAndUnsafeSql()
    {
        assertTrue(validator.isValidName("car_info"));
        assertFalse(validator.isValidName("CarInfo"));
        assertFalse(validator.isValidName("sys user"));
        assertTrue(validator.isAllowedColumnType("varchar(100)"));
        assertTrue(validator.isAllowedColumnType("decimal(10,2)"));
        assertTrue(validator.isAllowedColumnType("decimal(10,0)"));
        assertTrue(validator.isAllowedColumnType("decimal(65,30)"));
        assertFalse(validator.isAllowedColumnType("decimal(66,0)"));
        assertFalse(validator.isAllowedColumnType("decimal(65,31)"));
        assertFalse(validator.isAllowedColumnType("decimal(99,99)"));
        assertFalse(validator.isAllowedColumnType("decimal(5,9)"));
        assertFalse(validator.isAllowedColumnType("json"));
        assertFalse(validator.isSafeSql("drop table sys_user"));
    }
}
