Skip to content

Commit

Permalink
fix linter add link documentation readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Ddiidev committed Dec 17, 2023
1 parent 815fd46 commit e6af615
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 42 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Practical way to read and modify an ini/cfg file

## Documentação da API

You can access the documentation here. (WIP)
You can access the documentation [here](https://ldedev.github.io/ini-v/).

## Install

Expand Down
4 changes: 2 additions & 2 deletions deserialize.v
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn deserialize(content string) map[string]map[string]string {
current_line_bk := get_skip_line(content)

for line in content.split(current_line_bk) {
if line.len < ini.minimum_length_per_line {
if line.len < minimum_length_per_line {
continue
}

Expand All @@ -41,4 +41,4 @@ pub fn deserialize(content string) map[string]map[string]string {
}

return value
}
}
14 changes: 5 additions & 9 deletions io_deserialize.v
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@ import os
// println(s)
// ```
pub fn serrialize(content map[string]map[string]string) string {

mut data := ""
mut data := ''
for section in content.keys() {
data += "[$section]\n"
data += '[${section}]\n'
for key in content[section].keys() {
value := content[section][key]
data += "$key=$value\n"
data += '${key}=${value}\n'
}
}

return data
}


// write_ini writes the ini object to an ini format file.
//
// Example:
Expand All @@ -39,7 +37,7 @@ pub fn serrialize(content map[string]map[string]string) string {
// }
// }, './file.ini')!
// ```
pub fn write_ini(content map[string]map[string]string, path string)! {
pub fn write_ini(content map[string]map[string]string, path string) ! {
os.write_file(path, serrialize(content))!
}

Expand All @@ -51,8 +49,6 @@ pub fn write_ini(content map[string]map[string]string, path string)! {
// println(c['conf']['conf1'])
// ```
pub fn read_ini(content_or_path string) !map[string]map[string]string {
content := os.read_file(content_or_path) or {
return error("ini file not found")
}
content := os.read_file(content_or_path) or { return error('ini file not found') }
return deserialize(content)
}
8 changes: 3 additions & 5 deletions io_deserialize_to.v
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ import os
// ```
pub fn reader_to[T](pathOrContent string) !T {
mut data := T{}

if os.exists(pathOrContent) {
content := os.read_file(pathOrContent) or {
return error("ini file not found")
}
content := os.read_file(pathOrContent) or { return error('ini file not found') }
data = parser[T](content)!
} else if pathOrContent.len > 5 {
data = parser[T](pathOrContent)!
}

return data
}
}
6 changes: 1 addition & 5 deletions tests/deserialize_test.v
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module tests

import ini { deserialize , serrialize }
import ldedev.ini { deserialize }

fn test_parser_simples() {

ini_str := r'
[conf]
key=value
Expand All @@ -17,9 +16,7 @@ fn test_parser_simples() {
assert 'key2' in result['conf']
}


fn test_double_section() {

ini_str := r'
[conf]
key=value
Expand All @@ -39,7 +36,6 @@ fn test_double_section() {
}

fn test_with_space() {

ini_str := r'
[ conf ]
key= value
Expand Down
20 changes: 10 additions & 10 deletions tests/deserialize_to_test.v
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
module tests

import ini { reader_to }

import ldedev.ini { reader_to }

struct KeysIniAnon {
pub:
conf struct {
pub:
conf1 string
conf2 int
pub:
conf1 string
conf2 int
}

password struct {
pub:
pass1 string
valid bool
pub:
pass1 string
valid bool
}
}

struct KeysIni {
pub:
conf Conf
conf Conf
password Passwords
}

Expand Down Expand Up @@ -47,7 +47,7 @@ const str_ini = r'
'

fn test_parser_valid_true() {
local_ini := str_ini.replace('?', 'true')
local_ini := tests.str_ini.replace('?', 'true')
i1 := reader_to[KeysIni](local_ini)!
i2 := reader_to[KeysIniAnon](local_ini)!

Expand Down
20 changes: 11 additions & 9 deletions tests/ioini_test.v
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module tests

import os
import ini { deserialize, serrialize, write_ini, read_ini }
import ldedev.ini { deserialize, read_ini, serrialize, write_ini }

const ini_file_temp = 'temp_ini/test.ini'

Expand Down Expand Up @@ -37,9 +37,11 @@ fn test_read_ini() {
key1= my_key
key2= my_key2
'
os.write_file(ini_file_temp, ini_str) or { panic('could not write $ini_file_temp') }
os.write_file(tests.ini_file_temp, ini_str) or {
panic('could not write ${tests.ini_file_temp}')
}

pini := read_ini(ini_file_temp) or { panic('could not read $ini_file_temp') }
pini := read_ini(tests.ini_file_temp) or { panic('could not read ${tests.ini_file_temp}') }

assert pini.len == 2
assert pini['conf'].len == 2
Expand All @@ -53,15 +55,15 @@ fn test_write_ini() {
mut mini := map[string]map[string]string{}

mini['conf'] = {
'key': 'value'
'key': 'value'
'key2': ' value2'
}

write_ini(mini, ini_file_temp) or { panic('could not write $ini_file_temp') }
write_ini(mini, tests.ini_file_temp) or { panic('could not write ${tests.ini_file_temp}') }

pini := read_ini(ini_file_temp) or { panic('could not read $ini_file_temp') }
pini := read_ini(tests.ini_file_temp) or { panic('could not read ${tests.ini_file_temp}') }

assert os.exists(ini_file_temp)
assert os.exists(tests.ini_file_temp)
assert pini.len == 1
assert pini['conf'].len == 2

Expand All @@ -72,8 +74,8 @@ fn restart() {
if !os.exists('temp_ini') {
os.mkdir('temp_ini') or { panic('temp_ini directory already exists') }
} else {
if os.exists(ini_file_temp) {
os.rm(ini_file_temp) or { panic('could not remove temp ini file') }
if os.exists(tests.ini_file_temp) {
os.rm(tests.ini_file_temp) or { panic('could not remove temp ini file') }
}
os.rmdir('temp_ini') or { panic('could not remove temp_ini directory') }
}
Expand Down
2 changes: 1 addition & 1 deletion tool.v
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ fn get_skip_line(content &string) string {
'\n'
}
}
}
}

0 comments on commit e6af615

Please sign in to comment.