#GLEAM: strings

18 messages · Page 1 of 1 (latest)

thick oriole
#

Hi everyone!
I think I ight be too dumb for gleam cause I'm already stuck on the first string problem 😦

Instructions
In this exercise you'll be processing log-lines.

Each log line is a string formatted as follows: "[<LEVEL>]: <MESSAGE>".

There are three different log levels:

INFO
WARNING
ERROR
You have three tasks, each of which will take a log line and ask you to do something with it.

Implement the message function to return a log line's message:

message("[ERROR]: Invalid operation")
// -> "Invalid operation"
Any leading or trailing white space should be removed:

message("[WARNING]: Disk almost full\r\n")
// -> "Disk almost full"

Here's my code:
pub fn message(log_line: String) -> String { case log_line { "[INFO]: " <> message -> string.trim(message) "[WARNING]: " <> message -> string.trim(message) "[ERROR]: " <> message -> string.trim(message) _ -> "Invalid log message" } }
It's not passing all the tests cause it's returning ("[ERROR]: \t Corrupt disk\t \t \r\n") cause trim only removes the rest as long as it's a space it's my understanding, and it's also removing bits that I don't intend to such aslog_levels.reformat("[WARNING]: Decreased performance")
|> should.equal("Decreased performance (warning)") , am I supposed to stack another function here? not sure what the best way to go could be

bright apex
#

Could you copy paste an exact test code and failure?

thick oriole
#

Hi Isaac. Thanks for your response.
You mean this?

bright apex
#

I think so. Could you copy paste the text? Images are a terrible way to share text.

thick oriole
#

Yeah ofc. I was just making sure this is what you needed

bright apex
#

You can use a codeblock to make it readable

thick oriole
#

CODE RUN log_levels.reformat("[ERROR]: \t Corrupt disk\t \t \r\n") |> should.equal("Corrupt disk (error)") TEST FAILURE test/log_levels_test.gleam test: reformat_with_leading_and_trailing_white_space_test error: todo site: log_levels:17 info: This has not yet been implemented

bright apex
#

Do you understand what the test is doing?
Do you understand the test error message?

thick oriole
#

Yes - it is expecting that input "[ERROR]: \t Corrupt disk\t \t \r\n" returns
"Corrupt disk (error)

#

Oh wait this dailed test is from one of the next exercises I haven't even attempted yet

bright apex
#

What function is the test calling?

thick oriole
#

Sorry this is very confusing

#

Apologies. My mistake.

bright apex
#

No worries. Reading test details carefully is a skill that needs to be built up but is very valuable

cedar frigateBOT
#

If everything is resolved, we ask that the author of the top/original post react with a :white_check_mark: (:white_check_mark:). This indicates to others that this issue has been resolved and locks the thread.
If all the tests pass and you want to further improve your solution, we encourage you to use the "Request a Code Review" feature on the website!

thick oriole
#

I was just focusing on the first exercise and since I cannot see the actual tests until I run it

bright apex
#

Write code, run tests, read results, repeat.

dark pelican
#

I'm starting the Gleam track too. Unfortunately you need to either implement ALL the functions, or replace todo with some constant (of the same return type), for example ```pub fn reformat(log_line: String) -> String {
"todo"
}