Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
JavaScript agregando el carácter "·" a la línea final

Así que estoy tratando de ejecutar tests.js para un código python que he escrito, todo parece estar bien, sin embargo, al final de cada línea (carácter "\n"), el archivo tests.js agrega un carácter "·". . El archivo usa internamente el método toString() para convertir la salida de python en una cadena y luego la compara con la cadena esperada usando toEqual().

Mi código:

 def print_help(): print("""Usage :- $ ./task add 2 hello world # Add a new item with priority 2 and text "hello world" to the list $ ./task ls # Show incomplete priority list items sorted by priority in ascending order $ ./task del INDEX # Delete the incomplete item with the given index $ ./task done INDEX # Mark the incomplete item with the given index as complete $ ./task help # Show usage $ ./task report # Statistics""", end="")

La salida: error

El código tests.js:

 test("prints help", () => { let received = execSync(tasksTxtCli("help")).toString("utf8"); expect(received).toEqual(expect.stringContaining(usage)); });
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

No sé qué está usando para su salida en Node.js, pero es probable que este no sea en realidad un carácter de punto medio, sino un carácter no imprimible por su emulador de terminal.

En otras palabras, lo que estás viendo no está realmente allí. Es solo que algo está ahí.

Espero que esta sea una diferencia entre \r\n y \n para caracteres de nueva línea. Su cadena de comparación probablemente no tenga \r\n , pero la salida de Python probablemente sí.

Si quiere estar realmente seguro de lo que es, canalice su salida de Python a un archivo y ábralo con un editor hexadecimal. O incluso, simplemente no convierta a una cadena y use console.log() (o util.inspect() ) para ver una representación hexadecimal de la salida binaria.

about 4 years ago · Juan Pablo Isaza Report

0

Según mi solución, modifique su código como:

 def print_help(): help="""Usage :- $ ./task add 2 hello world # Add a new item with priority 2 and text "hello world" to the list $ ./task ls # Show incomplete priority list items sorted by priority in ascending order $ ./task del INDEX # Delete the incomplete item with the given index $ ./task done INDEX # Mark the incomplete item with the given index as complete $ ./task help # Show usage $ ./task report # Statistics""" sys.stdout.buffer.write(help.encode('utf8'))

De esta forma, el punto (.) no aparecerá en la línea de comandos. Referencia:https://github.com/nseadlc-2020/package-todo-cli-task/issues/12

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!